結果

問題 No.315 世界のなんとか3.5
ユーザー maspymaspy
提出日時 2020-05-05 18:59:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,537 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 10,708 KB
実行使用メモリ 13,244 KB
最終ジャッジ日時 2023-09-09 07:31:15
合計ジャッジ時間 7,839 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
8,068 KB
testcase_01 AC 61 ms
8,152 KB
testcase_02 AC 86 ms
8,152 KB
testcase_03 AC 88 ms
8,016 KB
testcase_04 AC 96 ms
8,076 KB
testcase_05 AC 84 ms
8,060 KB
testcase_06 AC 97 ms
8,088 KB
testcase_07 AC 84 ms
8,012 KB
testcase_08 AC 88 ms
8,088 KB
testcase_09 AC 77 ms
8,052 KB
testcase_10 AC 66 ms
8,052 KB
testcase_11 AC 85 ms
8,196 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 271 ms
13,068 KB
testcase_35 AC 322 ms
13,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

A, B, P = readline().split()

P = int(P)

A = [0, 0, 0, 0, 0] + [int(x) - ord('0') for x in A]
B = [0, 0, 0, 0, 0] + [int(x) - ord('0') for x in B]

def solve(A, P, include=True):
    total = 0
    no_3 = 0
    cnt = (0, 1, 2, 3, 3, 4, 5, 6, 7, 8)
    MOD3 = 3 * MOD
    for x in A[:-6]:
        total = (10 * total + x) % MOD3
        no_3 = (9 * no_3 + cnt[x]) % MOD
    n = no_3 * 3
    no_3 = [n, n, n]
    x = A[-6]
    full_use_3 = 3 in A[:-6]
    for d in range(x):
        if full_use_3 or d == 3:
            continue
        no_3[(total + d) % 3] += 1
    total = (total * 10 + x) % MOD3
    use_3 = (total - sum(no_3)) % MOD
    full_mod_3 = total % 3
    full_use_3 = 3 in A[:-5]
    U = 0
    for x in A[-5:]:
        U = 10 * U + x

    ret = 0
    for x in range(10**5):
        if x % P == 0:
            continue
        if '3' in str(x):
            ret += total
        else:
            ret += use_3 + no_3[(-x) % 3]

    for x in range(U + include):
        if x % P == 0:
            continue
        if '3' in str(x) or full_use_3:
            ret += 1
        else:
            ret += (full_mod_3 + x) % 3 == 0
    return ret

def solve_naive(A, P, include):
    N = A + include
    ret = 0
    for x in range(N + 1):
        if x % P == 0:
            continue
        ret += '3' in str(x) or x % 3 == 0
    return ret

x = solve(B, P, True) - solve(A, P, False)
print(x % MOD)
0