P1207 [USACO1.2] Dual Palindromes

Background

If a number reads the same from left to right and from right to left, then it is called a "palindrome." For example, $12321$ is a palindrome, while $77778$ is not. We do not allow leading zeros in the representation; therefore, $0220$ is not considered a palindrome. In fact, some numbers (such as $21$) are not palindromes in base $10$, but they are palindromes in other bases (for example, in base $2$ it is $10101$).

Description

Given two decimal integers $n, s$, find the first $n$ decimal numbers greater than $s$ that are palindromic in at least two bases among base $2$ through base $10$, and output them. A solution to this problem does not need integers wider than $32$ bits.

Input Format

One line containing two positive integers $n, s$ separated by a space.

Output Format

Output $n$ lines. Each line contains one number that satisfies the requirement, in ascending order.

Explanation/Hint

Constraints For $100\%$ of the testdata, $1 \le n \le 15$, $1 \le s \le 9999$. Problem translation from NOCOW. USACO Training Section 1.2. Translated by ChatGPT 5