#P1015. [NOIP 1999 普及组] 回文数
[NOIP 1999 普及组] 回文数
Description
If a number (with a nonzero leading digit) reads the same from left to right and from right to left, we call it a palindromic number.
For example: given the decimal number , adding and (i.e., reading from right to left) yields , which is a palindromic number.
Another example for the decimal number : STEP1: . STEP2: . STEP3: . STEP4: .
Here, one step means performing one addition in base . In the above example, it takes at least steps to obtain the palindromic number .
Write a program that, given a base ( or ) number (within digits), finds the minimum number of steps needed to obtain a palindromic number. If it is impossible to obtain a palindromic number within steps (inclusive), output Impossible!.
Input Format
Two lines: , then .
Output Format
If a palindromic number can be obtained within steps, output in the form STEP=ans, where is the minimum number of steps.
Otherwise, output Impossible!.
10
87
STEP=4
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号