CF1681D.Required Length

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 \cdot 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?

给你两个整数 nn 和 xx。你可以对整数 xx 执行若干次操作。

每次操作如下:选择 xx 的十进制表示中至少出现一次的任意数字 yy,并将 xx 替换为 x⋅yx \cdot y。

你希望使 xx 的十进制表示(不含前导零)的长度恰好等于 nn。实现这一目标所需的最少操作次数是多少?

输入格式

The only line of the input contains two integers nn and xx (2≤n≤192 \le n \le 19; 1≤x<10n−11 \le x \lt 10^{n-1}).

输入仅包含一行,有两个整数 nn 和 xx(2≤n≤192 \le n \le 19;1≤x<10n−11 \le x \lt 10^{n-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.

输出一个整数——使 xx 的十进制表示(不含前导零)的长度恰好等于 nn 所需的最少操作次数;如果不可能实现,则输出 −1-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:

  1. multiply xx by 22, so x=2⋅2=4x = 2 \cdot 2 = 4;
  2. multiply xx by 44, so x=4⋅4=16x = 4 \cdot 4 = 16;
  3. multiply xx by 66, so x=16⋅6=96x = 16 \cdot 6 = 96;
  4. multiply xx by 99, so x=96⋅9=864x = 96 \cdot 9 = 864.

在第二个例子中,以下操作序列可以达成目标:

  1. 将 xx 乘以 22,得到 x=2⋅2=4x = 2 \cdot 2 = 4;
  2. 将 xx 乘以 44,得到 x=4⋅4=16x = 4 \cdot 4 = 16;
  3. 将 xx 乘以 66,得到 x=16⋅6=96x = 16 \cdot 6 = 96;
  4. 将 xx 乘以 99,得到 x=96⋅9=864x = 96 \cdot 9 = 864。

输入解题思路,AI测评打分。不知道怎么写?

首页