Required Length solution codeforces
You are given two integer numbers, nn and xx. You may perform several operations with the integer xx.
Each operation you perform is the following one: choose any digit yy that occurs in the decimal representation of xx at least once, and replace xx by x⋅yx⋅y.
You want to make the length of decimal representation of xx (without leading zeroes) equal to nn. What is the minimum number of operations required to do that?
The only line of the input contains two integers nn and xx (2≤n≤192≤n≤19; 1≤x<10n−11≤x<10n−1).
Print one integer — the minimum number of operations required to make the length of decimal representation of xx (without leading zeroes) equal to nn, or −1−1 if it is impossible.
2 1
-1
3 2
4
13 42
12
In the second example, the following sequence of operations achieves the goal:
- multiply xx by 22, so x=2⋅2=4x=2⋅2=4;
- multiply xx by 44, so x=4⋅4=16x=4⋅4=16;
- multiply xx by 66, so x=16⋅6=96x=16⋅6=96;
- multiply xx by 99, so x=96⋅9=864x=96⋅9=864.
SOLUTION
“Click here“