#P16913. [JLCPC 2026] Map1e

    ID: 19231 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>数学吉林O2优化哈希 hashing2026省赛/邀请赛

[JLCPC 2026] Map1e

Problem Description

Given a positive integer NN, define the repunit number R(k)R(k) as the number consisting of kk digits of 11, that is, R(k)=111…1⏟k digits R(k) = \underbrace{111\ldots1}_{k \text{ digits }}.

Please find the largest positive integer kk such that R(k)R(k) is a divisor of NN, and output kk.

Note that R(1)=1R(1) = 1 is a divisor of every positive integer, so the answer is at least 11.

Input Format

The first line contains an integer TT (1≤T≤5×1051 \le T \le 5 \times 10^5), representing the number of test cases. Then follow TT blocks, each describing one test case:

  • The first line contains a positive integer NN (1≤∣N∣≤1051 \le |N| \le 10^5, where ∣N∣|N| denotes the number of decimal digits of NN; it is guaranteed that NN has no leading zeros).

It is guaranteed that ∑∣N∣≤5×105\sum |N| \le 5 \times 10^5.

Output Format

For each test case, output one positive integer kk per line.

3
1221
99
7
3
2
1

Hint

In the first sample, 1221=111×111221 = 111 \times 11, so R(3)=111R(3) = 111 is a divisor of NN. R(4)=1111R(4) = 1111 is not a divisor of NN, so the answer is 33.

In the second sample, 99=11×999 = 11 \times 9, so R(2)=11R(2) = 11 is a divisor of NN. R(3)=111>99R(3) = 111 > 99, so the answer is 22.

In the third sample, 77 is not a multiple of 1111, so the answer is 11.

Translated by ChatGPT 5