結果

問題 No.1252 数字根D
ユーザー ygd.
提出日時 2020-10-18 11:04:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 540 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-07-21 03:20:13
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for case in range(T):
  d,A,B = map(int,input().split())
  oriA = A+0
  a = 0
  while A > 0:
    a += A%d
    A = A//d
    if A == 0 and a >= d:
      A = a
      a = 0
  #print(a)
  num = B-oriA+1
  loop_num = num//(d-1)
  amari = num%(d-1)
  loop_wa = (1+d-1)*(d-1)//2
  if a + amari-1 >= d: #先頭に戻る
    amari_wa = loop_wa - ((a-1) + (a-(d-1-amari)))*(d-1-amari)//2
  else:
    amari_wa = (a + a + amari-1)*amari//2
  ans = loop_num*loop_wa + amari_wa
  #print(loop_num,amari,loop_wa,amari_wa)
  print(ans)
    
0