CF1681D.Required Length
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integer numbers, n and x . You may perform several operations with the integer x .
Each operation you perform is the following one: choose any digit y that occurs in the decimal representation of x at least once, and replace x by x⋅y .
You want to make the length of decimal representation of x (without leading zeroes) equal to n . What is the minimum number of operations required to do that?
输入格式
The only line of the input contains two integers n and x ( 2≤n≤19 ; 1≤x<10n−1 ).
输出格式
Print one integer — the minimum number of operations required to make the length of decimal representation of x (without leading zeroes) equal to n , or −1 if it is impossible.
输入输出样例
输入#1
2 1
输出#1
-1
输入#2
3 2
输出#2
4
输入#3
13 42
输出#3
12
说明/提示
In the second example, the following sequence of operations achieves the goal:
- multiply x by 2 , so x=2⋅2=4 ;
- multiply x by 4 , so x=4⋅4=16 ;
- multiply x by 6 , so x=16⋅6=96 ;
- multiply x by 9 , so x=96⋅9=864 .