General Palindromic Number (进制)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.
Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N > 0 in base b >= 2, where it is written in standard notation with k+1 digits ai as the sum of (aibi) for i from 0 to k. Here, as usual, 0 <= ai < b for all i and ak is non-zero. Then N is palindromic if and only if ai = ak-i for all i. Zero is written 0 in any base and is also palindromic by definition.
Given any non-negative decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.
Input Specification:
Each input file contains one test case. Each case consists of two non-negative numbers N and b, where 0 <= N <= 109 is the decimal number and 2 <= b <= 109 is the base. The numbers are separated by a space.
Output Specification:
For each test case, first print in one line "Yes" if N is a palindromic number in base b, or "No" if not. Then in the next line, print N as the number in base b in the form "ak ak-1 ... a0". Notice that there must be no extra space at the end of output.
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
#include <iostream>
using namespace std;
int shu[];
int main()
{
int n,b;
while(cin>>n)
{
cin>>b;
if(n==)
{
cout<<"Yes"<<endl;
cout<<<<endl;
}
else
{
int count=;
int tem=n;
while(tem)
{
shu[count++]=tem%b;
tem=tem/b;
}
int i,j;
bool bb=true;
for(i=,j=count-;i<=j;i++,j--)
if(shu[i]!=shu[j]) bb=false;
if(bb) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
bool fir=true;
for(i=count-;i>=;i--)
{
if(fir)
{
fir=false;
cout<<shu[i];
}
else cout<<" "<<shu[i];
}
cout<<endl;
}
}
return ;
}
General Palindromic Number (进制)的更多相关文章
- PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
- PAT1019:General Palindromic Number
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- PAT 甲级 1019 General Palindromic Number(20)(测试点分析)
1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
- 1019 General Palindromic Number (20 分)
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or ...
- PTA (Advanced Level) 1019 General Palindromic Number
General Palindromic Number A number that will be the same when it is written forwards or backwards i ...
- PAT甲级——1019 General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT 1019 General Palindromic Number
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
随机推荐
- cocos2d-x调度器原理
程序运行后每达到一帧的时间间隔就会执行一次mainLoop void CCDisplayLinkDirector::mainLoop(void) { //判断是否需要释放CCDirector,通常游戏 ...
- Android(java)学习笔记82:我们到底该如何处理异常?
我们到底该如何处理异常? 原则: 如果该功能内部可以将问题处理,用try,自己能解决就自己解决问题. 如果处理不了,交由调用者处理,这是用throws,自己不能解决的问题,我们就抛出去交个调用者解决这 ...
- SSIS 学习(0):企业离 BI 还有多远?【转】
上一篇文章<<企业需要BI吗?>>发表后,有一些网友反应:BI现在还不火:BI仅仅在一些大企业有用武之地,中小型企业只能是望其项背,遥不可及了:BI仅仅是一些花拳秀腿而已,如果 ...
- 开发一个struts2的实例
前面一篇博客(实现struts2框架)带大家对基于mvc业务流程熟悉了一下,现在我们就用对mvc实现最好的框架struts2来开发一个应用实例.虽然现在MyEclipse8.5以上版本已经开始支持St ...
- 关于php一些数组函数
array_column($array,"key") 将二维数组中的键名为key的数据生成一个新数组 array_unique($array) 去除重复值
- 高可用软件Keepalived
关于高可用软件Keepalived的使用及配置请参见:http://www.voidcn.com/blog/9124573/article/p-5990263.html
- 4k 对齐,你准备好了吗?
什么是 4k 对齐? 其实与 “ 4K对齐 ” 相关联的是一个叫做 “ 高级格式化 ” 的分区技术.“ 高级格式化 ” 是国际硬盘设备与材料协会为新型数据结构格式所采用的名称.这是主要鉴于目前的硬盘容 ...
- Laravel Eloquent 的条件不等于
方法一: 使用Eloquent的where where('id', '!=' , 2) 方法二: 使用Eloquent的whereNotIn ->whereNotIn( 'id', [2]) 参 ...
- Six important .NET concepts 【Turn】
Introduction This article will explain six important concepts: stack, heap, value types, reference t ...
- Linux 命令 - head: 打印文件的开头部分
命令格式 head [OPTION]... [FILE]... 命令参数 -c, --bytes=[-]K 显示每个文件的前 K 字节内容. -n, --lines=[-]K 显示每个文件的前 K 行 ...