题目 › usaco-1588

Strange Function

USACO 2026 Third · 铜组 · 2026-02 · L1 基础 · Python 3.11 · 时限 4 秒 · 测试点等分

查看原题跳到结果

题面

来源: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

auto(max)

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

auto(high)

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

auto(max)

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 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 36 行
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()