CF1681D.Required Length
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
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?
给你两个整数 n 和 x。你可以对整数 x 执行若干次操作。
每次操作如下:选择 x 的十进制表示中至少出现一次的任意数字 y,并将 x 替换为 x⋅y。
你希望使 x 的十进制表示(不含前导零)的长度恰好等于 n。实现这一目标所需的最少操作次数是多少?
输入格式
The only line of the input contains two integers n and x (2≤n≤19; 1≤x<10n−1).
输入仅包含一行,有两个整数 n 和 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.
输出一个整数——使 x 的十进制表示(不含前导零)的长度恰好等于 n 所需的最少操作次数;如果不可能实现,则输出 −1。
输入输出样例
输入#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.
在第二个例子中,以下操作序列可以达成目标:
- 将 x 乘以 2,得到 x=2⋅2=4;
- 将 x 乘以 4,得到 x=4⋅4=16;
- 将 x 乘以 6,得到 x=16⋅6=96;
- 将 x 乘以 9,得到 x=96⋅9=864。
输入解题思路,AI测评打分。不知道怎么写?