Palindrome Bases
InterviewTime limit1sMemory limit256 MB
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, means , and each digit in base 10 ranges from to .
Besides base 10, the bases used most often are base 2, base 8, and base 16. In base , each digit ranges from to , and going from right to left the weight of each position grows as .
For example, the decimal number is written in several bases as follows.
- Base 16:
- Base 8: ()
- Base 2: ()
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 , , and .
Given a decimal integer , write a program that finds every base () for which written in base is a palindrome.
Input
The first line contains an integer . ()
Output
Print every base for which written in base is a palindrome, one per line in increasing order. If there is no such , print nothing.