Palindrome Numbers
Time limit1sMemory limit128 MB
Given a decimal integer with up to 1000 digits, print its representation in each base from 2 to 10 where it reads as a palindrome.
- Level
Medium5 of 10
- Topics
- Math, String, Implementation
- Solved
- No attempts yet
Problem
A palindrome is a string that reads the same forwards and backwards. For example, ala and aa are palindromes, while adam is not.
Every integer can be written in base as , where each digit is an integer with .
The value of is . For example, the base-10 number has value , and the base-8 number has value .
Given an integer in base 10, write a program that finds every base among in which is a palindrome.
Input
The first line contains the integer . ()
Output
If is not a palindrome in any of the bases , print NIE. Otherwise, for each base in which is a palindrome, print the base and the representation of in base on their own line, in the format b m. Print the bases in increasing order of .
Hint
For example, is in base 2 and in base 4, so it is a palindrome in both. ()