pat1019. General Palindromic Number (20)
1019. General Palindromic Number (20)
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<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,b;
scanf("%d %d",&n,&b);
vector<int> v;
v.push_back(n%b);//注意n==0的情况!!
n/=b;
while(n){
v.push_back(n%b);
n=n/b;
}
int i;
for(i=;i<v.size()/;i++){
if(v[i]!=v[v.size()--i]){
break;
}
}
if(i==v.size()/){
printf("Yes");
}
else{
printf("No");
}
printf("\n");
printf("%d",v[v.size()-]);
for(i=v.size()-;i>=;i--){
printf(" %d",v[i]);
}
printf("\n");
return ;
}
pat1019. General Palindromic Number (20)的更多相关文章
- PAT1019:General Palindromic Number
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- 1019 General Palindromic Number (20)(20 point(s))
problem A number that will be the same when it is written forwards or backwards is known as a Palind ...
- PAT Advanced 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 1019. General Palindromic Number (20)
生词以及在文中意思 forward 向前地 backward 向后地 palindromic 回文的 base 基数(如十进制的10 和二进制的2) numeral system 数制 decimal ...
- PAT (Advanced Level) 1019. General Palindromic Number (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚
n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...
随机推荐
- Oauth Client Credentials Grant
http://www.cnblogs.com/dudu/p/4569857.html OAuth真是一个复杂的东东,即使你把OAuth规范倒背如流,在具体实现时也会无从下手.因此,Microsoft. ...
- [CentOS7] 设置语言环境
博主想要将英文环境(en_US.UTF-8)改为中文环境(zh_CN.UTF-8),有两种解决方法 一.临时解决方法 使用LANG=“zh_CN.UTF-8”,这个命令来实现,不过在重新登录的时候又会 ...
- [SinGuLaRiTy] KM算法
[SinGuLaRiTy-1018] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. Some Method Are Reproduced F ...
- Java与其它语言的比较
Java与C/C++相比.Java语言是一种完全的面对对象语言,虽然他的底层(运行时库)是用C语言开发 的,可是并不依赖于C.因为Java的运行是在运行时库的支持下运行的,所以运行的效率比起可以更接近 ...
- dedecms有缩略图则显示缩略图,没有则显示随机缩略图
随着html5以及扁平化等新的设计概念的深入人心,缩略图功能则成了一般网页模版制作不可或缺的一个功能,dedecms默认的的缩略图调用标签[field:imglink/] 或者 [field:litp ...
- Java之批处理的实现
批处理(batch) 一.批处理介绍 1. 批处理指的是一次操作中执行多条SQL语句 2. 批处理相比于一次一次执行效率会提高很多 3. 批处理主要是分两步: 1.将要执行的SQL语句保存 2.执行S ...
- luogu4449 于神之怒加强版(莫比乌斯反演)
link 给定n,m,k,计算\(\sum_{i=1}^n\sum_{j=1}^m\gcd(i,j)^k\)对1000000007取模的结果 多组数据,T<=2000,1<=N,M,K&l ...
- Codeforces Round #549 div2 1143-B Nirvana 题解
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater v ...
- c语言定义指针类型需注意事项
1)在定义说明语句中,指针变量名之前的星号“*“是指针变量的修饰符,也就是说它所修饰的变量是指针变量. 2)指针变量是用它们所指向的对象类型来区分的.如定义 int *ip,类型int并不是指针的类型 ...
- P2596 [ZJOI2006]书架(splay)
[题目链接] https://www.luogu.org/problemnew/show/P2596 平衡树,需支持五个操作: 1. 将某元素置顶:将元素旋到根,然后将左子树合并到该元素的后继 2. ...