题面
来源:USACO 官网。模型收到的是同一份题面的文字。
For all positive integers $x$, the function $f(x)$ is defined as follows:
- If $x$ has any digits that aren't $0$ or $1$, for each digit of $x$, set it to $1$ if it is odd or $0$ otherwise, and return $x$.
- Otherwise, return $x-1$.
Given a value of $x$ ($1 \leq x < 10^{2\cdot 10^5}$), find how many times $f$ needs to be applied to $x$ until $x$ reaches $0$. As this number might be very large, output its remainder when divided by $10^9+7$.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains $T$ ($1\le T\le 10^5$), the number of independent tests.The next $T$ lines each contain a positive integer $x$ consisting solely of the digits 0-9, with no leading zeros.
It is guaranteed that the total number of digits in all input integers does not exceed $10^6$.
OUTPUT FORMAT (print output to the terminal / stdout):
For each test case, output the remainder of the number of times when divided by $10^9+7$ on a separate line.SAMPLE INPUT:
2 24680 210
SAMPLE OUTPUT:
1 4
First test: $x$ becomes zero after one operation.
Second test: $f(x)=10, f^2(x)=9, f^3(x)=1, f^4(x)=0$
SAMPLE INPUT:
1 1234567890123456789012345678901234567890
SAMPLE OUTPUT:
511620083
SCORING:
- Inputs 3-5: $T\le 2000$, $x< 10^{9}$
- Inputs 6-7: $x<10^{18}$
- Inputs 8-9: $x<10^{60}$
- Inputs 10-12: No additional constraints.
Problem credits: Aidan Bai
结果
Kimi K3.1 ProKimi
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 4.7k平均输出 token(含思考) ↓
- 32.9输出速度 tokens/s ↑
- 144 秒延迟 ↓
- 0.26×CPU 时间 / 官方解 ↓
- 不确定时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 9.09Pylint 得分 ↑
- 5圈复杂度 ↓
- 78.1可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 11.0k平均输出 token(含思考) ↓
- 207.2输出速度 tokens/s ↑
- 53 秒延迟 ↓
- 0.25×CPU 时间 / 官方解 ↓
- 不确定时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 9.35Pylint 得分 ↑
- 7圈复杂度 ↓
- 48.0可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 8.8k平均输出 token(含思考) ↓
- 209.7输出速度 tokens/s ↑
- 43 秒延迟 ↓
- 0.26×CPU 时间 / 官方解 ↓
- 不确定时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 9.26Pylint 得分 ↑
- 6圈复杂度 ↓
- 73.7可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
import sys MOD = 1_000_000_007 MOD2 = 2 * MOD def main(): data = sys.stdin.buffer.read().split() t = int(data[0]) answers = [] for i in range(1, t + 1): s = data[i] n = 0 transformed = False # Interpreting the parity digits as a binary number gives n. # If no transformation is needed, these digits equal the original ones. for c in s: if c > 49: # A digit other than '0' or '1' transformed = True n = ((n << 1) + (c & 1)) % MOD2 # The number of operations after obtaining n is floor(3*n/2). # Using n modulo 2*MOD preserves both the result modulo MOD and parity. ans = (3 * n - (n & 1)) // 2 if transformed: ans += 1 answers.append(str(ans % MOD)) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": main()
import sys MOD = 1_000_000_007 INV2 = (MOD + 1) // 2 def solve() -> None: data = sys.stdin.buffer.read().split() if not data: return t = int(data[0]) out = [] idx = 1 for _ in range(t): s = data[idx] idx += 1 b = 0 has_non_binary_digit = False for ch in s: d = ch - 48 parity = d & 1 b = (b * 2 + parity) % MOD if d > 1: has_non_binary_digit = True last_parity = (s[-1] - 48) & 1 if last_parity: h = ((3 * b - 1) % MOD) * INV2 % MOD else: h = (3 * b % MOD) * INV2 % MOD if has_non_binary_digit: h += 1 out.append(str(h % MOD)) sys.stdout.write("\n".join(out)) if __name__ == "__main__": solve()
import sys MOD = 1_000_000_007 INV2 = 500_000_004 def solve(): data = sys.stdin.buffer.read().split() if not data: return t = int(data[0]) answers = [] for i in range(1, t + 1): s = data[i] b_mod = 0 has_invalid_digit = False for ch in s: digit = ch - 48 # ASCII digit to integer if digit > 1: has_invalid_digit = True # Parity of the original digit. bit = digit & 1 # Interpret the parity digits as a binary number. b_mod = (2 * b_mod + bit) % MOD # The parity of b is the parity of its last binary digit. parity = (s[-1] - 48) & 1 # floor(3b / 2) = (3b - (b mod 2)) / 2 answer = ((3 * b_mod - parity) * INV2) % MOD if has_invalid_digit: answer = (answer + 1) % MOD answers.append(str(answer)) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": solve()