#t253. 回文数
回文数
Palindrome Number
Problem Description
If a number (with no leading zero) reads the same from left to right as from right to left, we call it a palindrome number.
For example, given the decimal number , adding (i.e. reading backwards) gives , which is a palindrome.
Another example, for the decimal number :
- STEP1:
- STEP2:
- STEP3:
- STEP4:
Here one "step" means one addition in base . The example above reaches the palindrome in steps at least.
Write a program that, given an -ary number ( or , and has at most digits), computes the minimum number of steps to obtain a palindrome. If it is impossible to obtain a palindrome within steps (inclusive), output Impossible!.
Input Format
Two lines: and , respectively.
Output Format
If a palindrome can be obtained within steps, output in the form STEP=ans, where is the minimum number of steps.
Otherwise output Impossible!.
Sample Input
Sample Input 1
10
87
Sample Output
Sample Output 1
STEP=4