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

题目分析:按照求在不同进制下的数 来就十进制数 与原数进行比较
 #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int Array[];
int Tag;
int main()
{
int N, b;
cin >> N >> b;
int n = ;
int temp = N;
int t=;
while (N)
{
t = N % b;
Array[Tag++] = t;
n = n*b + t;
N /= b;
}
if (n == temp)
cout << "Yes"<<endl;
else
cout << "No"<<endl;
cout << Array[--Tag];
while (Tag)
cout << " " << Array[--Tag];
return ;
}

最新文章

  1. eclipse 中的注释 快捷键
  2. [转]PHP5 session 详解
  3. logback.xml日志配置
  4. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(6)
  5. 使用Script元素发送JSONP请求
  6. leetcode 逆转字符串 当年的第一题,今天再写一遍,物是人非
  7. 三、C# 运算符和控制流
  8. 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼
  9. 八、桥接模式--结构模式(Structural Pattern)
  10. SPOJ PT07X Vertex Cover
  11. ASP.NET MVC 使用MSBuild部署的几个注意事项
  12. MySQL学习笔记(二)&mdash;查询
  13. 【Android Developers Training】 74. 序言:通过无线连接设备
  14. 开源纯C#工控网关+组态软件(三)加入一个新驱动:西门子S7
  15. 认证模式之Basic模式
  16. iOS和OS X中的bundle
  17. [转]CAS原理
  18. C# -- 使用FileInfo获取文件信息
  19. Linux学习笔记(一):常用命令(1)
  20. js 实用小技巧

热门文章

  1. MySQL 【教程一】
  2. Simulink仿真入门到精通(十) S函数
  3. Python包的应用
  4. 一键配置openstack-cata版的在线yum源
  5. Ng-Matero V9 正式发布!
  6. 【转】分布式架构的演进(JavaWeb)
  7. Java 并发原子操作类(转)
  8. 安卓App自动化测试环境
  9. TCP IP Socket In C, 2e-chapter 1 Introduction
  10. VUE npm run dev 启动时,报了一大堆错误 Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 7.x