結果

問題 No.2032 Let's Write Multiples!!
ユーザー ShirotsumeShirotsume
提出日時 2022-07-15 02:07:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,154 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 80,268 KB
最終ジャッジ日時 2023-09-08 18:27:57
合計ジャッジ時間 9,810 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,660 KB
testcase_01 AC 456 ms
80,268 KB
testcase_02 AC 827 ms
79,232 KB
testcase_03 AC 867 ms
79,364 KB
testcase_04 AC 253 ms
78,672 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
INF = 2 ** 63 - 1
mod = 998244353
def floor_sum(N, M, a, b):
    res = 0
    while N:
        q, a = divmod(a, M)
        res += N * (N - 1) // 2 * q
        q, b = divmod(b, M)
        res += N * q
        N, b = divmod(a * N + b, M)
        a, M = M, a
    return res

 
def f(r, k, c):
    n = r // k
    ans = 0
    for i in range(1, 10):
        d = 10 ** i
        x = c * (d // 10)
        y = (c + 1) * (d // 10)
        ans += n - floor_sum(n, d, k, d + k) + floor_sum(n, d, k,  d + k - x)
        if c < 9:
            ans -= n - floor_sum(n, d, k, d + k) + floor_sum(n, d, k, d + k - y)
    return ans
    
def solve(l, r, k, c):
    if k > 10 ** 4:
        return solve_gu(l, r, k, c)
    return f(r, k, c) - f(l - 1, k, c)

def solve_gu(l, r, k, c):
    s = (l + k - 1) // k
    t = r // k
    ans = 0
    for i in range(s, t + 1):
        now = k * i
        while now > 0:
            if now % 10 == c:
                ans += 1
            now //= 10
    return ans

for _ in range(ii()):
    l, r, k, c = mi()
    print(solve(l, r, k, c))
0