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 ∑i=0k(aibi). 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 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<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
水题:进制转换,判断是否回文
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-24-01.08.29
* Description : A1019
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
;
bool judge(int s[],int len){
;i<len;i++){
]){
return false;
}
}
return true;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int a,n;
scanf("%d%d",&a,&n);
,s[maxn]={};
do{
s[num++]=a%n;
a/=n;
}while(a);
if(judge(s,num)){
printf("Yes\n");
}
else{
printf("No\n");
}
;i>=;i--){
printf("%d",s[i]);
) printf(" ");
}
;
}
1019 General Palindromic Number (20 分)的更多相关文章
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- 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 ...
- 【PAT甲级】1019 General Palindromic Number (20 分)
题意: 输入两个正整数n和b(n<=1e9,2<=b<=1e9),分别表示数字的大小和进制大小,求在b进制下n是否是一个回文串,输出“Yes”or“No”,并将数字n在b进制下打印出 ...
- 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 ...
- 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 ...
- PAT A1019 General Palindromic Number (20 分)
AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...
随机推荐
- Windows 7 + PHP 5.3 + WAMP 下 Imagick 扩展安装
1.首先,下载 ImageMagick 安装包.下载地址 下载后运行此安装包.在系统环境变量中添加 MAGICK_HOME 变量,指向安装目录下的modules\coders. 2.下载 Imagic ...
- 0107 for循环练习
//画菱形 for(int hs = 1; hs < 11; hs++) { //画空格 for(int kg = 9; kg >= hs; kg--) { System.out.prin ...
- 《C语言中分配了动态内存后一定要释放吗?》
问:比如main函数里有一句 malloc(),后面没有free()1.那么当main结束后,动态分配的内存不会随之释放吗?2.如果程序结束能自动释放,那么还加上free(),是出于什么考虑? 答: ...
- kbmMW集成JWT
如果对JWT不熟悉,需要先补下功课:初步理解JWT并实践使用 然后找到开源项目:https://github.com/paolo-rossi/delphi-jose-jwt
- UITableView去掉分隔符
或用代码实现 [TableView setSeparatorColor:[UIColor clearColor]]; 问题一用你给的方法貌似不行,我用这个方法把分隔线给“去掉”了: [editV ...
- 2.2 linux中的信号分析
信号: 信号是UNIX系统响应某些状况而产生的事件,进程在接收到信号时会采取相应的行动. 信号是因为某些错误条件而产生的,比如内存段冲突.浮点处理器错误或者非法指令等. 信号是在软件层次上对中断的一种 ...
- DS18B20配置
复位脉冲: 先拉低至少480us,以产生复位脉冲,接着释放4.7k电阻为高,延时15~60us, 进入接收. void DS18B20_Rst(void) { DS18B20_IO_OUT(); // ...
- 五个对你有用的Everything搜索技巧
分享五个对你有用的Everything搜索技巧: 一, empty:(查找空文件夹);二, dupe:(查重复文档);三, 空格(与), |(或),!(非); 四, e:\ (路径搜索);五, wil ...
- Codeforces1106F 【BSGS】【矩阵快速幂】【exgcd】
首先矩阵快速幂可以算出来第k项的指数,然后可以利用原根的性质,用bsgs和exgcd把答案解出来 #include<bits/stdc++.h> using namespace std; ...
- hdu2098 分拆素数和 素数筛
将一个偶数拆成两个素数的和,欧拉筛暴力 #include<stdio.h> #include<string.h> #define N 10001 ]; ]; ,j; void ...