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. 最简单好用的SSO - 能经得起几万并发用户的SSO 组件使用方法介绍

    项目中使用了通用权限管理系统,该系统集成了单点登录功能,下面我来介绍下该单点登录实现的一些细节. 首先我们来看看其登录接口,系统本身支持各种登录方式: 1.公司名.用户名.密码 2.唯一账号.密码 3 ...

  2. 安装openshift客户端工具 rhc

    安装ruby: $ sudo apt-get install ruby-full 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 将会安装下列额外的软件包: ...

  3. Debian apt-get 无法补全

    今天发现在终端里输入apt-get inst后按Tab键无法自动补全成 install,纳闷之余google了一下(我承认开始是baidu...),原来是没有安装 bash-completion. s ...

  4. hihocoder 1066 无间道之并查集

    #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...

  5. 1172 Hankson 的趣味题

    1172 Hankson 的趣味题 2009年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Descrip ...

  6. white-space:nowrap 的妙用

    对于多个元素同在同一行的布局,如比较常见的是轮播.下面我将探讨这这一布局的做法: 首先约定html结果如下: div.row div.col div.col div.col ... 做法一: 设定di ...

  7. http keepalive

    转载自: http://www.92csz.com/17/1152.html http keepalive 在http早期 ,每个http请求都要求打开一个tpc socket连接,并且使用一次之后就 ...

  8. JMS - Exceptions

    The JMSException JMS defines JMSException as the root class for exceptions thrown by JMS methods. JM ...

  9. C#算法基础之插入排序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 【转】Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline

    相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的: