#P1207. [USACO1.2] Dual Palindromes

[USACO1.2] Dual Palindromes

题目背景

If a number reads the same from left to right and from right to left, then it is called a "palindrome." For example, 1232112321 is a palindrome, while 7777877778 is not. We do not allow leading zeros in the representation; therefore, 02200220 is not considered a palindrome.

In fact, some numbers (such as 2121) are not palindromes in base 1010, but they are palindromes in other bases (for example, in base 22 it is 1010110101).

题目描述

A number that reads the same from right to left as when read from left to right is called a palindrome. The number 1232112321 is a palindrome; the number 7777877778 is not. Palindromes have neither leading nor trailing zeroes, so 02200220 is not a palindrome.

The number 2121 (base 1010) is not a palindrome in base 1010, but the number 2121 (base 1010) is a palindrome in base 22 (1010110101).

Write a program that reads two numbers expressed in base 1010:

  • NN (1N151 \le N \le 15)
  • SS (0<S<100000 < S < 10000)

Then find and print (in base 1010) the first NN numbers strictly greater than SS that are palindromic when written in two or more number bases (2base102 \le \text{base} \le 10).

Solutions to this problem do not require manipulating integers larger than the standard 3232 bits.

输入格式

A single line with space separated integers NN and SS.

输出格式

NN lines, each with a base 1010 number that is palindromic when expressed in at least two of the bases 2..102..10. The numbers should be listed in order from smallest to largest.

3 25

26
27
28

提示

USACO Training Section 1.2.