結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,212 KB
testcase_01 AC 74 ms
71,104 KB
testcase_02 AC 76 ms
70,700 KB
testcase_03 AC 86 ms
75,364 KB
testcase_04 AC 94 ms
76,524 KB
testcase_05 AC 93 ms
76,112 KB
testcase_06 AC 93 ms
76,368 KB
testcase_07 AC 93 ms
76,280 KB
testcase_08 AC 92 ms
76,392 KB
testcase_09 AC 94 ms
76,276 KB
testcase_10 AC 93 ms
76,728 KB
testcase_11 AC 93 ms
76,452 KB
testcase_12 AC 93 ms
76,368 KB
testcase_13 AC 93 ms
76,388 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())
    print( f(B,d)-f(A-1,d) )
0