結果

問題 No.1252 数字根D
ユーザー marroncastlemarroncastle
提出日時 2020-10-09 21:58:29
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 76,924 KB
最終ジャッジ日時 2023-09-27 16:50:42
合計ジャッジ時間 2,349 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,292 KB
testcase_01 AC 67 ms
71,412 KB
testcase_02 AC 68 ms
71,216 KB
testcase_03 AC 127 ms
76,924 KB
testcase_04 AC 86 ms
76,640 KB
testcase_05 AC 87 ms
76,808 KB
testcase_06 AC 84 ms
76,612 KB
testcase_07 AC 83 ms
76,800 KB
testcase_08 AC 81 ms
76,676 KB
testcase_09 AC 84 ms
76,680 KB
testcase_10 AC 81 ms
76,672 KB
testcase_11 AC 83 ms
76,864 KB
testcase_12 AC 85 ms
76,636 KB
testcase_13 AC 85 ms
76,592 KB
testcase_14 AC 64 ms
71,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [0]*T
for t in range(T):
  d, A, B = map(int, input().split())
  a = A
  fa = 0
  while a>=d:
    while a>0:
      fa += a%d
      a //= d
    a = fa
    fa = 0
  n = B-A+1
  if n<d-a:
    ans[t] = (a+(a+B-A))*(B-A+1)//2
    continue
  ans[t] += (a+(d-1))*(d-a)//2
  cyc, mod = divmod(B-A+1-(d-a),d-1)
  ans[t] += d*(d-1)//2*cyc+mod*(mod+1)//2
print(*ans, sep='\n')
0