結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
51,968 KB
testcase_01 AC 46 ms
51,968 KB
testcase_02 AC 48 ms
52,480 KB
testcase_03 AC 75 ms
64,512 KB
testcase_04 AC 91 ms
72,064 KB
testcase_05 AC 95 ms
72,320 KB
testcase_06 AC 85 ms
72,320 KB
testcase_07 AC 87 ms
72,192 KB
testcase_08 AC 88 ms
72,320 KB
testcase_09 AC 85 ms
72,320 KB
testcase_10 AC 85 ms
72,064 KB
testcase_11 AC 87 ms
72,320 KB
testcase_12 AC 84 ms
72,320 KB
testcase_13 AC 85 ms
72,320 KB
testcase_14 AC 42 ms
51,584 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(k+1,D)
    assert 0<=A<=B<=10**9,"(第{}テストケース)A,Bが範囲外(A={},B={})".format(k+1,A,B)

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