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. Linux 同步时间

    Linux里有2个时间: 硬件时间 系统时间 这2个时间不是同步的!如果有一天发现系统的时间不对了,可以分别看看这2个时间.硬件时间写在BIOS里,系统时间就是电脑显示的时间了. sudo hwclo ...

  2. [BigData]关于Hadoop学习笔记第二天(PPT总结)(一)

    Plan: 分布式文件系统与HDFS HDFS体系结构与基本概念 HDFS的shell操作 java接口及常用api HADOOP的RPC机制 HDFS源码分析 远程debug 自己设计一分布式文件系 ...

  3. 练习题之Wait/Notify

    方案一: public class PrintABC { public static void main(String[] args) { AtomicInteger synObj = ); Runn ...

  4. CF 19D - Points 线段树套平衡树

    题目在这: 给出三种操作: 1.增加点(x,y) 2.删除点(x,y) 3.询问在点(x,y)右上方的点,如果有相同,输出最左边的,如果还有相同,输出最低的那个点 分析: 线段树套平衡树. 我们先离散 ...

  5. ENVI/IDL与ArcGIS集成开发的三种途径

    转载:本文来自ENVI5.0-IDL8.2系列产品白皮书_201303.PDF(Esri中国官网可下载)中P7-P10 ENVI 是一个非常开放的平台,提供一个健全的函数库,几乎涵盖ENVI 平台大部 ...

  6. Emmet 语法大全(缩写语法/sublime 插件)

    Emmet 使用类似于 CSS 选择器的语法描述元素在生成的文档树中的位置及其属性. 元素 可以使用元素名(如 div 或者 p)来生成 HTML 标签.Emmet 没有预定义的有效元素名的集合,可以 ...

  7. 有些方法为什么会声明称static静态的

    有些方法在调用的时候,没有必要都要先实例化一下,只需要:[类名. 静态方法 ]就行了. 哪些方法的调用没有必要实例化呢?网上找了个例子: 举个例子:Car类,1.静态方法Run(),Car.Run() ...

  8. Xcode6:The file couldn’t be opened because you don’t have permission to view it

    最近为了兼容iOS8升级到Xcode6.0编译之前的工程,结果App无法在真机上运行.报错如下: The file “xxxx.app” couldn’t be opened because you ...

  9. DWR应用—快速入门篇

    DWR(Direct Web Remoting)是一个Ajax的开源框架,用于改善web页面与Java类交互的远程服务器端的交互体验. 官网:http://directwebremoting.org/ ...

  10. OC1_点语法

    // // Dog.h // OC1_点语法 // // Created by zhangxueming on 15/6/16. // Copyright (c) 2015年 zhangxueming ...