1019 General Palindromic Number
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
Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.
Each input file contains one test case. Each case consists of two positive numbers N and b, where 0 For each test case, first print in one line 自己写的代码: 这里直接用了int 类型的sum来存储转换后的值,会存在爆int的可能,比如:n=5000,b=2,这样会超过int的表示范围,还是用数组来存储比较好! (2022.11.1)这样的代码如果遇到基数超过10的就会发生错误,入 19 20 在20进制下,结果19其实就是一个一位的数字,但这个代码会判断为两位数,最终发生错误 学习到的小技巧: 将数字转化成任意进制的数: 大佬的代码: 例子: a=18 b=20; 这样的例子对结果是不会有影响的,由于a!=0,所以index=1,不会执行中间的循环,所以后面flag肯定执行打印 yes 2022.11.1(第二次写) 好好学习,天天向上! 我要考研!Output Specification:
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:
Sample Input 2:
121 5
Sample Output 2: