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 ...
随机推荐
- jqcss选择器
$("p").css("background-color","red"); $(this) 当前 HTML 元素$("p" ...
- Java之MySql数据库链接
一 下载MySql驱动包,下载途径很多,随便Google或度娘一下就有,我下载的是mysql-connector-java-5.1.26版本,下载后把它解压到指定路径 二 在Eclipse中新建项目T ...
- linux-统计行数
wc -l ls |wc -l 查看文件夹下的行数 cat/less/more +文件名|wc -l
- PHPnow开启PHP扩展里openssl支持的方法
PHPnow 是 Win32 下绿色的 Apache + PHP + MySQL 环境套件包.简易安装.快速搭建支持虚拟主机的 PHP 环境.更多介绍<PHP服务套件 PHPnow1.5.6&g ...
- P6Spy 、 SQL Profiler
P6Spy 在优化Hibernate性能的时候,很重要的一点就是要看到Hibernate底层执行的SQL 虽然通过打印日志配合Hibernate的show_sql属性能够拼凑出Hibernate底层执 ...
- Linux(CentOS)安装rar和unrar以及rar和unrar命令的使用
可以参考此篇博文. http://www.cnblogs.com/linjiqin/archive/2013/03/24/2979736.html 不过我按照其步骤手动安装Linux的rar文件执 ...
- [未完成]关于POI的使用
关于POI的使用关于POI的使用关于POI的使用关于POI的使用
- 封装SqliteHelper类--Sqlite数据库
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- IP地址计算和划分
一. B类地址 范围从128-191(第一串8位二进制10000000~10111111),如172.168.1.1,第一和第二段号码为网络号码,剩下的2段号码为本地计算机的号码.转换为2进 ...
- winform 渐变(非API)
public FrmMain() { InitializeComponent(); //窗体显示特效 Opacity = 0.0; //窗体透明度为0 fadeTimer.Start(); //计时开 ...