結果

問題 No.1252 数字根D
ユーザー tonyu0tonyu0
提出日時 2020-10-09 23:05:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 721 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 12,528 KB
最終ジャッジ日時 2023-09-27 19:25:47
合計ジャッジ時間 4,385 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
7,796 KB
testcase_01 AC 17 ms
7,928 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())


def digit_sum(x, d):
    while x >= d:
        tmp = 0
        while x > 0:
            tmp += x % d
            x //= d
        x = tmp
    return x


for _ in range(t):
    d, a, b = map(int, input().split())
    left = digit_sum(a, d)
    right = digit_sum(b, d)

    # one_cycle = (d - 1) * d // 2
    # cycle_len = d - 1
    n = b - a + 1

    # ds = digit_sum(a, d)
    ans = 0
    # ans = n // cycle_len * one_cycle
    # head = one_cycle - (left - 1) * left // 2 if left != 1 else 0
    # tail = right * (right + 1) // 2 if right < d - 1 else 0
    for i in range(n):
        ans += left
        left += 1
        if left == d:
            left = 1
    #print(ans + head + tail)
    print(ans)
0