#abc313e. E - Duplicate
E - Duplicate
Score : points
问题描述
对于由数字1至9组成的字符串 ,令 为通过以下过程得到的字符串 。其中, 表示 的第 个字符。
- 初始化一个空字符串 。
- 对于 ,执行以下操作:
- 将 解释为整数时的值 ,将 的 个副本追加到 的末尾。
例如,当 313 时,按照以下步骤可得 3111。
- 初始为空。
- 当 时,我们有 。向 追加一个
3的副本,使其变为3。 - 当 时,我们有 。向 追加三个
1的副本,使其变为3111。 - 结束该过程。我们得到
3111。
给定一个长度为 、由数字1至9组成的字符串 。
您需要重复以下操作,直到字符串 的长度变为 :用 替换 。
求出在完成操作之前,你需要进行此操作的次数,并对 取模。如果该操作会无限重复,请输出 -1。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
For a string consisting of digits from 1 through 9, let be the string obtained by the following procedure. ( denotes the -th character of .)
- Let be an initially empty string.
- For , perform the following operation:
- Append copies of to the tail of , where is the value when is interpreted as an integer.
For example, 313 yields 3111 by the following steps.
- is initially empty.
- For , we have . Append one copy of
3to , which becomes3. - For , we have . Append three copies of
1to , which becomes3111. - Terminate the procedure. We obtain
3111.
You are given a length- string consisting of digits from 1 through 9.
You repeat the following operation until the length of becomes : replace with .
Find how many times, modulo , you perform the operation until you complete it. If you will repeat the operation indefinitely, print -1 instead.
Constraints
- is a length- string consisting of
1,2,3,4,5,6,7,8, and9.
Input
The input is given from Standard Input in the following format:
Output
Print the number of times, modulo , that you perform the operation until you complete it. If you will repeat the operation indefinitely, print -1 instead.
Sample Input 1
3
313
Sample Output 1
4
If 313, the length of be comes after four operations.
- We have
3111. Replace with3111. - We have
311. Replace with311. - We have
31. Replace with31. - We have
3. Replace with3. - Now that the length of is , terminate the repetition.
Sample Input 2
9
123456789
Sample Output 2
-1
If 123456789, you indefinitely repeat the operation. In this case, -1 should be printed.
Sample Input 3
2
11
Sample Output 3
1
update @ 2024/3/10 08:56:04