結果

問題 No.8133 ‮Reversed‪
コンテスト
ユーザー K2
提出日時 2026-04-01 22:48:25
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 998 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 230 ms
コンパイル使用メモリ 85,680 KB
実行使用メモリ 435,196 KB
最終ジャッジ日時 2026-04-01 22:48:56
合計ジャッジ時間 11,343 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def rev(n: int):
    return int(str(n)[::-1])

MOD = 7 * 10 ** 9 + 1

pow10 = [1] * 20
for i in range(1, 20):
    pow10[i] = (pow10[i - 1] * 10) % MOD

memo = {}


def solve(n: int):
    assert n >= 0
    if n in memo:
        return memo[n]

    if n < 100:
        res = 0
        for i in range(1, n + 1):
            res += rev(i)
        memo[n] = res
        return res

    s = str(n)
    L = len(s)
    res = 45

    for i in range(2, L):
        x = pow10[i - 1] - 1
        y = pow10[i - 2] - 1
        res += 45 * pow10[i - 1] * (x - y)
        res %= MOD

    x = int(s[:-1])
    y = pow10[L - 2] - 1
    res += 10 * solve(x - 1)
    res += 45 * pow10[L - 1] * (x - 1 - y)
    res %= MOD
    
    v = int(s[-1])
    res += (v + 1) * rev(x)
    res += v * (v + 1) // 2 * pow10[L - 1]
    res %= MOD

    memo[n] = res
    return res


N = int(input())
for i in range(N):
    l, r = map(int, input().split())
    res = solve(r) - solve(l - 1)
    res %= MOD
    # print(i)
    print(res)
0