B. Renzo and the palindromic decoration

Codeforces
IDCF10104B
Time2000ms
Memory64MB
Difficulty
English · Original
Formal · Original
At the ruins of Wat Phra Si Sanphet (วดพระศรสรรเพชญ), one can find famous inscriptions that have only recently been decoded. Several numbers written using Thai numerals decorate these ruins. A couple of years ago, the famous Peruvian researcher Renzo "el intrépido" Morales found out that most numbers found at the ruins are palindromic, that is, they represent the same number when read backwards. For instance, 171 is palindromic, whereas 17 is not. Intrigued by the existence of non palidromic numbers as decorations in the ruins, Renzo found out that, while these numbers are not palindromic when represented in base 10 (which is the base used in the Thai numeral system), they are palindromic when represented in another base. For b > 0, the base-b representation of a number N is the sequence amam - 1... a1a0 so that 0 ≤ ai ≤ b - 1 for each 0 ≤ i ≤ m, am ≠ 0, and To validate his discovery, Renzo wants you to write a program that takes a number represented in base 10 and checks in which bases from 2 to 16 such number has a palindromic representation. The first line has a single integer T, the number of test cases. Each test case has a single line with an integer N written in base 10. For each test case, print in a single line a space-separated list of integers, from 2 to 16 and in increasing order, of the bases for which the representation of N is palindromic. If N does not have a palindromic representation for any of the bases from 2 to 16, print _-1_. *Limits* ## Input The first line has a single integer T, the number of test cases.Each test case has a single line with an integer N written in base 10. ## Output For each test case, print in a single line a space-separated list of integers, from 2 to 16 and in increasing order, of the bases for which the representation of N is palindromic. If N does not have a palindromic representation for any of the bases from 2 to 16, print _-1_.*Limits* 0 ≤ T ≤ 103 0 ≤ N < 231 [samples]
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case, let $ N \in \mathbb{Z}^+ $ be a positive integer represented in base 10. **Constraints** 1. $ 1 \leq T \leq 1000 $ 2. $ 1 \leq N \leq 10^9 $ **Objective** For each $ N $, determine the set $ B_N \subseteq \{2, 3, \dots, 16\} $ such that the base-$ b $ representation of $ N $ is palindromic. The base-$ b $ representation of $ N $ is the sequence $ (a_m, a_{m-1}, \dots, a_0) $ where: - $ N = \sum_{i=0}^{m} a_i b^i $, - $ 0 \leq a_i < b $ for all $ i $, - $ a_m \neq 0 $, - and $ (a_m, a_{m-1}, \dots, a_0) = (a_0, a_1, \dots, a_m) $ (i.e., the digit sequence is a palindrome). Output $ B_N $ in increasing order. If $ B_N = \emptyset $, output $ -1 $.
API Response (JSON)
{
  "problem": {
    "name": "B. Renzo and the palindromic decoration",
    "description": {
      "content": "At the ruins of Wat Phra Si Sanphet (วดพระศรสรรเพชญ), one can find famous inscriptions that have only recently been decoded. Several numbers written using Thai numerals decorate these ruins. A couple",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10104B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "At the ruins of Wat Phra Si Sanphet (วดพระศรสรรเพชญ), one can find famous inscriptions that have only recently been decoded. Several numbers written using Thai numerals decorate these ruins.\n\nA couple...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case, let $ N \\in \\mathbb{Z}^+ $ be a positive integer represented in base 10.\n\n**Constraints**  \n1. $ 1 \\leq T ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments