結果

問題 No.1252 数字根D
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-10 02:10:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 76,900 KB
最終ジャッジ日時 2023-09-27 20:57:12
合計ジャッジ時間 2,292 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,040 KB
testcase_01 AC 68 ms
71,112 KB
testcase_02 AC 67 ms
71,184 KB
testcase_03 AC 77 ms
75,520 KB
testcase_04 AC 88 ms
76,588 KB
testcase_05 AC 87 ms
76,344 KB
testcase_06 AC 87 ms
76,592 KB
testcase_07 AC 86 ms
76,900 KB
testcase_08 AC 84 ms
76,708 KB
testcase_09 AC 85 ms
76,728 KB
testcase_10 AC 86 ms
76,496 KB
testcase_11 AC 85 ms
76,652 KB
testcase_12 AC 86 ms
76,616 KB
testcase_13 AC 86 ms
76,688 KB
testcase_14 AC 67 ms
71,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1252

桁ごとに和を取っていき、1桁にする演算
それをd進法でやる
A以上B以下に関してその総和を求める

0以上X以下の答え=f(X)さえ求められれば
f(B)-f(A-1)で答えが求まる

3進法で検証
0
1
2
10,1
11,2
12,10,1
20,2
21,10,1
22,11,2
100,1

→1,2,3…dを繰り返す?

"""

def Dsum(num,d):
    #print (num,d)
    if num < d:
        return num
    ret = 0
    while num > 0:
        ret += num % d
        num //= d
    return Dsum(ret,d)

def f(x,d):

    ans = (x // (d-1)) * (d * (d-1) // 2)
    rem = x % (d-1)
    ans += (1+rem) * rem // 2

    return ans

from sys import stdin

TT = int(stdin.readline())

for loop in range(TT):

    d,A,B = map(int,stdin.readline().split())
    if A == B == 0:
        print (0)
        continue
    if A == 0:
        A += 1
    print( f(B,d)-f(A-1,d) )
0