結果

問題 No.1252 数字根D
ユーザー ygd.ygd.
提出日時 2020-10-18 11:06:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 1,183 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 77,760 KB
最終ジャッジ日時 2023-09-28 08:50:05
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,140 KB
testcase_01 AC 63 ms
71,212 KB
testcase_02 AC 68 ms
71,276 KB
testcase_03 AC 107 ms
77,752 KB
testcase_04 AC 127 ms
77,540 KB
testcase_05 AC 120 ms
77,520 KB
testcase_06 AC 119 ms
77,564 KB
testcase_07 AC 112 ms
77,536 KB
testcase_08 AC 122 ms
77,632 KB
testcase_09 AC 111 ms
77,688 KB
testcase_10 AC 122 ms
77,548 KB
testcase_11 AC 115 ms
77,480 KB
testcase_12 AC 112 ms
77,760 KB
testcase_13 AC 119 ms
77,488 KB
testcase_14 AC 63 ms
71,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for case in range(T):
  d,A,B = map(int,input().split())
  if A == B == 0:
    print(0);continue
  if A == 0:
    A += 1
  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