結果

問題 No.1252 数字根D
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-10 02:08:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 76,752 KB
最終ジャッジ日時 2023-09-27 20:56:40
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,964 KB
testcase_01 AC 66 ms
71,432 KB
testcase_02 AC 66 ms
71,352 KB
testcase_03 AC 74 ms
75,540 KB
testcase_04 AC 84 ms
76,676 KB
testcase_05 AC 85 ms
76,524 KB
testcase_06 AC 86 ms
76,620 KB
testcase_07 AC 86 ms
76,688 KB
testcase_08 AC 87 ms
76,676 KB
testcase_09 AC 88 ms
76,644 KB
testcase_10 AC 88 ms
76,628 KB
testcase_11 AC 86 ms
76,628 KB
testcase_12 AC 86 ms
76,752 KB
testcase_13 AC 83 ms
76,604 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
    else:
        print( f(B,d)-f(A-1,d) )
0