Palindrome in Some Base
InterviewTime limit1sMemory limit256 MB
For each N, decide whether its base B representation is a palindrome for some B from 2 to 64.
- Level
Easy3 of 10
- Topics
- Math, Brute force, Simulation
- Solved
- No attempts yet
Problem
A number is a palindrome when it reads the same from left to right and from right to left. For example, 747 is a palindrome in base 10. 255 is not a palindrome in base 10, but written in base 16 it is FF, so it is a palindrome there.
Given a positive integer , decide whether some base with writes as a palindrome. Base means one position holds one of possible values. In base 10, is 10. When is larger than 10, treat the value of each position as a single digit and compare those values, and write the representation without a leading zero.
Input
Input comes from standard input. The first line has the number of test data . Each of the next lines has one integer . Every satisfies 64 to 1,000,000 inclusive.
Output
Output goes to standard output. Print one line per test datum. Print 1 if some base with writes as a palindrome, and 0 if no such base exists.