結果

問題 No.1252 数字根D
ユーザー proriboneproribone
提出日時 2020-10-09 23:09:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 81,376 KB
最終ジャッジ日時 2023-09-27 19:33:00
合計ジャッジ時間 3,434 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
70,964 KB
testcase_01 AC 81 ms
75,612 KB
testcase_02 AC 80 ms
75,732 KB
testcase_03 AC 116 ms
78,284 KB
testcase_04 AC 150 ms
80,968 KB
testcase_05 AC 151 ms
81,324 KB
testcase_06 AC 167 ms
81,216 KB
testcase_07 AC 161 ms
80,732 KB
testcase_08 AC 153 ms
80,692 KB
testcase_09 AC 154 ms
81,376 KB
testcase_10 AC 152 ms
81,040 KB
testcase_11 AC 154 ms
80,876 KB
testcase_12 AC 151 ms
80,980 KB
testcase_13 AC 154 ms
81,192 KB
testcase_14 AC 64 ms
71,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


def solve():
    def digit(x):
        res=0
        while(x>0):
            res+=x%d
            x//=d
        return res
    
    def f(m,N):
        if m==0:
            return N
        return digit(f(m-1,N))
    
    d,A,B=map(int,input().split())
    if A==0:
        A+=1
    if B==0:
        return 0
    
    Ares,Bres=f(30,A),f(30,B)
    if (B-A+1)<=(d-1) and Ares<Bres:
        return (Ares+Bres)*(Bres-Ares+1)//2
    
    ans=(Ares+d-1)*(d-Ares)//2
    A+=d-Ares
    dif=(B-A)
    roop=dif//(d-1)
    ans+=roop*(d*(d-1)//2)
    ans+=(1+Bres)*(Bres)//2
    return ans
    
    

t=int(input())
for _ in range(t):
    print(solve())
0