luogu#P1207. [USACO1.2] 双重回文数 Dual Palindromes

[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, 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).

Problem Description

Given two decimal integers n,sn, s, find the first nn decimal numbers greater than ss that are palindromic in at least two bases among base 22 through base 1010, and output them.

A solution to this problem does not need integers wider than 3232 bits.

Input Format

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

Output Format

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

3 25

26
27
28

Hint

Constraints
For 100%100\% of the testdata, 1n151 \le n \le 15, 1s99991 \le s \le 9999.

Problem translation from NOCOW.

USACO Training Section 1.2.

Translated by ChatGPT 5