#abc222g. G - 222

G - 222

Score : 600600 points

问题描述

我们有一个序列 2,22,222,2222,2,22,222,2222,\ldots,其中第 ii 项是一个由全部为 22 的数字组成的 ii 位整数。

在这个序列中,首次出现 KK 的倍数是在哪个位置?如果第一个 KK 的倍数是序列中的第 xx 项,则输出 xx;如果没有 KK 的倍数出现,则输出 -1

给定 TT 个测试用例,请分别解决它们。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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

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

Given TT cases, solve each of them.

Constraints

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

Input

Input is given from Standard Input in the following format:

TT

case1\text{case}_1

case2\text{case}_2

\vdots

caseT\text{case}_T

Each case is in the following format:

KK

Output

Print TT lines. The ii-th line should contain the answer for casei\text{case}_i.

Sample Input 1

4
1
7
10
999983

Sample Output 1

1
6
-1
999982

We have four cases.

  • 22 is a multiple of 11.
  • None of 2,22,222,2222,222222,22,222,2222,22222 is a multiple of 77, but 222222222222 is.
  • None of 2,22,2,22,\ldots is a multiple of 1010.

update @ 2024/3/10 09:48:11