#P1207. Multi-base Palindrome Search
Multi-base Palindrome Search
Multi-base Palindrome Search
Given two decimal numbers \(n\) and \(s\), find the first \(n\) decimal numbers that are greater than \(s\) and are palindromic in at least two bases (from binary to decimal). A number is said to be palindromic in a base if its representation in that base reads the same forwards and backwards. Note that the solution does not require using integers larger than 32-bit.
Definition:
For a given positive integer \(x\) and a base \(b\) (where \(2 \le b \le 10\)), let \(f(x, b)\) be the representation of \(x\) in base \(b\). The number \(x\) is said to be palindromic in base \(b\) if:
\[ f(x, b) = \text{reverse}(f(x, b)) \]Find the first \(n\) numbers (in decimal) that are greater than \(s\) and have at least two bases \(b\) (with \(2 \le b \le 10\)) for which the above condition holds.
inputFormat
The input consists of two space-separated integers: \(n\) and \(s\).
\(n\) represents the number of valid numbers to find and \(s\) is the threshold. Only numbers greater than \(s\) are considered.
outputFormat
Output exactly \(n\) numbers, each on a new line. These numbers are the first \(n\) decimal numbers greater than \(s\) that are palindromic in at least two bases among bases 2 to 10.
sample
2 5
7
8
</p>