CF1681D.Required Length

普及/提高-

通过率:0%

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

输入格式

The only line of the input contains two integers nn and xx ( 2n192 \le n \le 19 ; 1x<10n11 \le x < 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.

输入输出样例

  • 输入#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=22=4x = 2 \cdot 2 = 4 ;
  2. multiply xx by 44 , so x=44=16x = 4 \cdot 4 = 16 ;
  3. multiply xx by 66 , so x=166=96x = 16 \cdot 6 = 96 ;
  4. multiply xx by 99 , so x=969=864x = 96 \cdot 9 = 864 .
首页