結果

問題 No.1252 数字根D
ユーザー proriboneproribone
提出日時 2020-10-09 23:08:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 640 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 81,528 KB
最終ジャッジ日時 2023-09-27 19:32:39
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,464 KB
testcase_01 AC 80 ms
75,732 KB
testcase_02 AC 81 ms
75,680 KB
testcase_03 AC 115 ms
78,352 KB
testcase_04 AC 147 ms
81,096 KB
testcase_05 AC 155 ms
81,528 KB
testcase_06 AC 153 ms
81,348 KB
testcase_07 AC 153 ms
81,176 KB
testcase_08 AC 151 ms
80,636 KB
testcase_09 AC 149 ms
81,384 KB
testcase_10 AC 143 ms
81,176 KB
testcase_11 AC 155 ms
81,228 KB
testcase_12 AC 145 ms
81,164 KB
testcase_13 AC 152 ms
81,296 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

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:
        B+=1
    
    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