A number n may look like a palindrome in some positional bases but not others. For each base b with 2 <= b <= n-1, write n in base b as a sequence of digit values and check whether that sequence reads the same forwards and backwards. Count how many such bases make n a palindrome.
A single line with one integer n.
A single integer: the number of bases b in 2..n-1 in which n is a palindrome.
Example 1
Input
5
Expected
2
Explanation
In base 2, 5 is 101 (palindrome); in base 3 it is 12 (not); in base 4 it is 11 (palindrome). So 2 bases qualify.
Example 2
Input
3
Expected
1
Explanation
The only base considered is 2, where 3 is 11, a palindrome, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →