結果

問題 No.2032 Let's Write Multiples!!
ユーザー とりゐとりゐ
提出日時 2022-07-29 10:40:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 716 ms / 3,000 ms
コード長 651 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 86,700 KB
実行使用メモリ 81,576 KB
最終ジャッジ日時 2023-09-28 13:54:05
合計ジャッジ時間 13,460 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,336 KB
testcase_01 AC 332 ms
80,592 KB
testcase_02 AC 257 ms
79,792 KB
testcase_03 AC 241 ms
79,140 KB
testcase_04 AC 309 ms
79,908 KB
testcase_05 AC 677 ms
81,044 KB
testcase_06 AC 629 ms
80,800 KB
testcase_07 AC 388 ms
81,576 KB
testcase_08 AC 692 ms
80,340 KB
testcase_09 AC 112 ms
77,200 KB
testcase_10 AC 716 ms
80,376 KB
testcase_11 AC 707 ms
80,496 KB
testcase_12 AC 703 ms
80,436 KB
testcase_13 AC 715 ms
80,388 KB
testcase_14 AC 633 ms
80,216 KB
testcase_15 AC 304 ms
80,156 KB
testcase_16 AC 304 ms
80,048 KB
testcase_17 AC 303 ms
80,712 KB
testcase_18 AC 679 ms
81,160 KB
testcase_19 AC 421 ms
80,320 KB
testcase_20 AC 303 ms
79,812 KB
testcase_21 AC 279 ms
79,260 KB
testcase_22 AC 285 ms
79,556 KB
testcase_23 AC 292 ms
80,744 KB
testcase_24 AC 280 ms
79,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def floor_sum(n,m,a,b):
  ans=0
  while True:
    if a>=m:
      ans+=(n-1)*n*(a//m)//2
      a%=m
    if b>=m:
      ans+=n*(b//m)
      b%=m
    y_max=(a*n+b)//m
    x_max=(y_max*m-b)
    if y_max==0:
      return ans
    ans+=(n-(x_max+a-1)//a)*y_max
    n,m,a,b=y_max,a,m,(a-x_max%a)%a

          

from sys import stdin
input=lambda :stdin.readline()[:-1]

t=int(input())
for _ in range(t):
  L,R,K,C=map(int,input().split())
  L=(L+K-1)//K*K
  R=(R//K)*K
  if L>R:
    print(0)
    continue

  N=(R-L)//K+1
  ans=0
  for i in range(9):
    ans+=floor_sum(N,10**(i+1),K,L+10**i*(10-C))
    ans-=floor_sum(N,10**(i+1),K,L+10**i*(9-C))
  print(ans)
0