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 (进制)的更多相关文章

  1. PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  2. PAT1019:General Palindromic Number

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  3. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

  4. PAT 1019 General Palindromic Number[简单]

    1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...

  5. 1019 General Palindromic Number (20 分)

    1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or ...

  6. 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 ...

  7. 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 ...

  8. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  9. PAT 1019 General Palindromic Number

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

随机推荐

  1. ASP.NET MVC 4 批量上传文件

    上传文件的经典写法: <form id="uploadform" action="/Home/UploadFile" method="post& ...

  2. 代理和 block 传值的使用

    // // ZYViewController.h // BlockTest // // Created by yejiong on 14/11/2. // Copyright © 2014年 zzz. ...

  3. JavaScript开发之路02(Sencha Touch使用时常见问题及解决办法)

    1.Sencha中使用组件后通过layout: 'vbox'指定页面布局为垂直盒布局并且组件的高度采用height: '百分比'指定时,组件的背景色通过style: 'background:#F6F6 ...

  4. Hummer框架平台介绍

    三年工作过程中经常会用到使用Java开源框架,但经常会遇到重新组合比较麻烦,本次采用目前主流开源框架及插件整理出一套融合开发.测试.部署整个流程的平台. 本平台采用Hummer代号,是悍马和蜂鸟分意思 ...

  5. CentOS-6.5安装配置Tomcat7

    一.下载tomcat cd /usr/local/src wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.50/bin/apache ...

  6. [转].NET进阶系列之一:C#正则表达式整理备忘

    本文转自:http://www.cnblogs.com/KissKnife/archive/2008/03/23/1118423.html 有一段时间,正则表达式学习很火热很潮流,当时在CSDN一天就 ...

  7. 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项.试图加载格式不正确的程序

    .NET:Microsoft Visual Studio 2010 + .NET Framework 3.5 操作系统:windows2008 R2 64 位操作系统 oracle数据库:32位的OD ...

  8. 【策略】UVa 1344 - Tian Ji -- The Horse Racing(田忌赛马)

    Here is a famous story in Chinese history. That was about 2300 years ago. General Tian Ji was a high ...

  9. hdu 4005 边连通度与缩点

    思路:先将图进行缩点,建成一颗树,那么如果这是一条单路径树(即最大点度不超过2),就不在能删的一条边,使得不连通.因为将其头尾相连,形成一个圈,那么删任意一条边,图都是连通的. 上面的是无解的情况,如 ...

  10. Linux 命令 - traceroute: 数据报传输路径追踪

    traceroute 工具用于跟踪数据报的传输路径:当数据报从一台计算机传向另一台计算机时,会经过多重的网关,traceroute 命令能够找到数据报传输路径上的所有路由器.通过 traceroute ...