102226: [AtCoder]ABC222 G - 222

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

We have a sequence $2,22,222,2222,\ldots$, where the $i$-th term is an $i$-digit integer whose digits are all $2$.

Where does a multiple of $K$ appear in this sequence for the first time? If the first multiple of $K$ is the $x$-th term of the sequence, print $x$; if there is no multiple of $K$, print -1.

Given $T$ cases, solve each of them.

Constraints

  • $1 \leq T \leq 200$
  • $1 \leq K \leq 10^8$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$

Each case is in the following format:

$K$

Output

Print $T$ lines. The $i$-th line should contain the answer for $\text{case}_i$.


Sample Input 1

4
1
7
10
999983

Sample Output 1

1
6
-1
999982

We have four cases.

  • $2$ is a multiple of $1$.
  • None of $2,22,222,2222,22222$ is a multiple of $7$, but $222222$ is.
  • None of $2,22,\ldots$ is a multiple of $10$.

Input

题意翻译

定义数组 $A=\{2,22,222,2222,...\}$ ,给出 $q$ 次询问,每次询问给出一个数 $k$,求最小的 $x$ 使得 $A_x$ 是 $k$ 的倍数。 **样例解释** 对于样例中 $k=1$,有 $A_1=2$ 满足条件。 对于样例中 $k=7$,有 $A_6=222222$ 满足条件,并且 $A_1\sim A_5$ 均不符合条件。

Output

分数:$600$分

问题描述

我们有一个序列$2,22,222,2222,\ldots$,其中第$i$项是一个$i$位整数,其数字全部为$2$。

在这个序列中,$K$的倍数第一次出现在哪里?如果$K$的第一个倍数是序列中的第$x$项,输出$x$;如果没有$K$的倍数,输出-1

给定$T$个测试用例,解决每个测试用例。

约束

  • $1 \leq T \leq 200$
  • $1 \leq K \leq 10^8$
  • 输入中的所有值都是整数。

输入

从标准输入以以下格式给出输入:

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$

每个测试用例以以下格式给出:

$K$

输出

输出$T$行。第$i$行应包含$\text{case}_i$的答案。


样例输入1

4
1
7
10
999983

样例输出1

1
6
-1
999982

我们有四个测试用例。

  • $2$是$1$的倍数。
  • $2,22,222,2222,22222$中没有一个数是$7$的倍数,但$222222$是。
  • $2,22,\ldots$中没有一个数是$10$的倍数。

加入题单

算法标签: