Under construction

Still being built. Things may change

Palindrome Bases

Interview

Time limit1sMemory limit256 MB

Summary
For a given X, list every base b with 2 <= b < X in which X is written as a palindrome.
Level

Medium4 of 10

Topics
Math, Brute force, Implementation
Solved
No attempts yet

Problem

People have ten fingers, so we use base 10. For example, 257257 means 2×102+5×101+7×1002 \times 10^2 + 5 \times 10^1 + 7 \times 10^0, and each digit in base 10 ranges from 00 to 99.

Besides base 10, the bases used most often are base 2, base 8, and base 16. In base bb, each digit ranges from 00 to b−1b-1, and going from right to left the weight of each position grows as b0,b1,b2,…b^0, b^1, b^2, \dots.

For example, the decimal number 99 is written in several bases as follows.

  • Base 16: 99
  • Base 8: 1111 (1×81+1×80=91 \times 8^1 + 1 \times 8^0 = 9)
  • Base 2: 10011001 (1×23+0×22+0×21+1×20=91 \times 2^3 + 0 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 = 9)

All three of these representations are palindromes. A palindrome is a sequence that reads the same forwards and backwards. English examples include "dad", "mom", and "racecar"; numeric examples include 99, 1111, and 10011001.

Given a decimal integer XX, write a program that finds every base bb (2≤b<X2 \le b < X) for which XX written in base bb is a palindrome.

Input

The first line contains an integer XX. (2≤X≤1,000,000,0002 \le X \le 1{,}000{,}000{,}000)

Output

Print every base bb for which XX written in base bb is a palindrome, one per line in increasing order. If there is no such bb, print nothing.

Examples1

  1. Example 1

    Input
    9
    
    Expected output
    2
    8