結果

問題 No.1252 数字根D
ユーザー ygd.ygd.
提出日時 2020-10-18 11:04:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 540 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 78,160 KB
最終ジャッジ日時 2023-09-28 08:49:42
合計ジャッジ時間 3,314 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,388 KB
testcase_01 AC 78 ms
71,560 KB
testcase_02 AC 79 ms
71,360 KB
testcase_03 AC 122 ms
78,160 KB
testcase_04 AC 149 ms
77,788 KB
testcase_05 AC 144 ms
77,604 KB
testcase_06 AC 146 ms
77,764 KB
testcase_07 AC 136 ms
77,908 KB
testcase_08 AC 145 ms
77,784 KB
testcase_09 AC 134 ms
77,964 KB
testcase_10 AC 142 ms
77,784 KB
testcase_11 AC 138 ms
77,824 KB
testcase_12 AC 135 ms
78,008 KB
testcase_13 AC 137 ms
77,852 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

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