結果

問題 No.1252 数字根D
ユーザー 👑 KazunKazun
提出日時 2020-08-25 01:16:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 72,448 KB
最終ジャッジ日時 2024-04-25 04:23:39
合計ジャッジ時間 1,926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,096 KB
testcase_01 AC 42 ms
52,224 KB
testcase_02 AC 46 ms
52,736 KB
testcase_03 AC 69 ms
64,256 KB
testcase_04 AC 84 ms
72,320 KB
testcase_05 AC 85 ms
72,448 KB
testcase_06 AC 84 ms
72,320 KB
testcase_07 AC 86 ms
72,320 KB
testcase_08 AC 86 ms
72,320 KB
testcase_09 AC 85 ms
72,064 KB
testcase_10 AC 84 ms
72,448 KB
testcase_11 AC 82 ms
72,320 KB
testcase_12 AC 85 ms
72,064 KB
testcase_13 AC 87 ms
72,448 KB
testcase_14 AC 41 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def g(N):
    if N==0:
        return 0

    if N%(D-1)==0:
        Q=N//(D-1)
        R=0
    else:
        Q=N//(D-1)+1
        R=D-1-N%(D-1)

    return Q*(D*(D-1))//2-D*R+(R*(R+1))//2

T=int(input())
assert 1<=T<=2000,"Tが範囲外(T={})".format(T)

X=[0]*T
for k in range(T):
    D,A,B=map(int,input().split())
    assert 2<=D<=10**9,"Dが範囲外(D={})".format(D)
    assert 0<=A<=B<=10**9,"A,Bが範囲外(A={},B={})".format(A,B)

    X[k]=g(B)-g(max(A-1,0))
print("\n".join(map(str,X)))
0