10125 - 双重回文数

如果一个数从左往右读和从右往左读都是一样,那么这个数就叫做“回文数”。例如,12321就是一个回文数,而77778就不是。当然,回文数的首和尾都应是非零的,因此0220就不是回文数。 事实上,有一些数(如21),在十进制时不是回文数,但在其它进制(如二进制时为10101)时就是回文数。 编一个程序,从文件读入两个十进制数

N (1 <= N <= 15) S (0 < S < 10000) 然后找出前N个满足大于S且在两种以上进制(二进制至十进制)上是回文数的十进制数,输出到文件上。 本问题的解决方案不需要使用大于4字节的整型变量。

输入

只有一行,用空格隔开的两个数N和S。

输出

N行, 每行一个满足上述要求的数,并按从小到大的顺序输出。

样例

输入

3 25 

输出

26
27
28

提示

Dual Palindromes Mario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same from right to left as when read from left to right is called a palindrome. The number 12321 is a palindrome; the number 77778 is not. Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome.

The number 21 (base 10) is not palindrome in base 10, but the number 21 (base 10) is, in fact, a palindrome in base 2 (10101).

Write a program that reads two numbers (expressed in base 10):

N (1 <= N <= 15) S (0 < S < 10000) and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10). Solutions to this problem do not require manipulating integers larger than the standard 32 bits.

PROGRAM NAME: dualpal INPUT FORMAT A single line with space separated integers N and S.

SAMPLE INPUT (file dualpal.in) 3 25

OUTPUT FORMAT N lines, each with a base 10 number that is palindromic when expressed in at least two of the bases 2..10. The numbers should be listed in order from smallest to largest. SAMPLE OUTPUT (file dualpal.out) 26 27 28

时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题