#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 5656, adding 5656 and 6565 (i.e., reading 5656 from right to left) yields 121121, which is a palindromic number.

Another example for the decimal number 8787: STEP1: 87+78=16587+78=165. STEP2: 165+561=726165+561=726. STEP3: 726+627=1353726+627=1353. STEP4: 1353+3531=48841353+3531=4884.

Here, one step means performing one addition in base NN. In the above example, it takes at least 44 steps to obtain the palindromic number 48844884.

Write a program that, given a base NN (2N102 \le N \le 10 or N=16N=16) number MM (within 100100 digits), finds the minimum number of steps needed to obtain a palindromic number. If it is impossible to obtain a palindromic number within 3030 steps (inclusive), output Impossible!.

Input Format

Two lines: NN, then MM.

Output Format

If a palindromic number can be obtained within 3030 steps, output in the form STEP=ans, where ans\text{ans} is the minimum number of steps.

Otherwise, output Impossible!.

10
87

STEP=4

Hint

Translated by ChatGPT 5