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 a​i​​ as (. Here, as usual, 0 for all i and a​k​​ is non-zero. Then N is palindromic if and only if a​i​​=a​k−i​​ for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any positive 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 positive numbers N and b, where 0 is the decimal number and 2 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 "a​k​​ a​k−1​​ ... a​0​​". 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>
#include <vector>
using namespace std;
//此处11进制中的10就是10,而不是a
int main()
{
int N, b;
cin >> N >> b;
vector<int>v1, v2;
while (N)
{
v1.push_back(N%b);
N /= b;
}
v2.assign(v1.rbegin(), v1.rend());
if (v1 == v2)
cout << "Yes" << endl;
else
cout << "No" << endl;
if (v2.size() == )
cout << ;
else
{
cout << v2[];
for (int i = ; i < v2.size(); ++i)
cout << " " << v2[i];
}
cout << endl;
return ;
}

最新文章

  1. Apache 安装配置详情
  2. 【OpenJudge 1793】矩形覆盖
  3. js中的console很强大
  4. AFNetworking(AFN)总结
  5. Centos上Docker 使用dockerfile构建容器实现ssh
  6. .net获取select控件中的文本内容
  7. 【python】在python中调用mysql
  8. 上传至应用商店以及testflight相关。
  9. 修改linux文件/文件夹权限
  10. [转]oracle误删数据的恢复
  11. 妙味H5交互篇备忘
  12. Code Sign error: No code signing identities found: No valid signing identities
  13. centos7下编译安装mysql
  14. Java入门——(1)Java编程基础
  15. crm 数据展示 和分页思想(一)
  16. 金蝶K3 WISE BOM多级展开_销售成本表
  17. socket端口绑定后通过bat干掉
  18. 491. Increasing Subsequences
  19. STM32f103的数电采集电路的DMA设计和使用优化程序
  20. Kindle2018 一周使用报告

热门文章

  1. VS2015遇到的自带报表的问题
  2. Vue的组件及传参
  3. SQLAlchemy的out join
  4. WPF基础之Grid面板
  5. SQL中的左连接与右连接,内连接有什么不同
  6. 【左偏树】 [JLOI2015]城池攻占
  7. c# 中反射里的invoke方法的参数
  8. react中使用屏保
  9. 多项式模板&amp;题目整理
  10. linux 解压 WinRAR 压缩文件