NOIP '99 P2 - Palindrome Numbers

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem types

If a number where the first digit is not 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 56, the sum of 56+65 (i.e. 56 read from right to left) is 121 which is a palindrome number.

Another example for decimal number 87:

STEP 1: 87+78 = 165

STEP 2: 165+561 = 726

STEP 3: 726+627 = 1353

STEP 4: 1353+3531 = 4884

A step here refers to one addition done in base N. The above example used 4 steps to get a palindrome number, 4884.

Given the base N (2 \le N \le 10 \text{ or } N = 16) and the initial number M (less than or equal to 100 digits) in base N, find the minimum steps to get a palindrome number. If it is impossible to get a palindrome number in less than or exactly 30 steps, output Impossible!.

Input Specification

The first line will contain N.

The second line will contain M.

Output Specification

If you can get a palindrome number within 30 steps, output the number of steps in the form of STEP=ans, where ans is the minimum number of steps to get a palindrome number. Otherwise, output Impossible!.

Sample Input

10
87

Sample Output

STEP=4

Problem translated to English by Tommy_Shan.


Comments

There are no comments at the moment.