結果

問題 No.2032 Let's Write Multiples!!
ユーザー とりゐとりゐ
提出日時 2022-07-20 12:55:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,583 ms / 3,000 ms
コード長 660 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 100,296 KB
最終ジャッジ日時 2023-09-15 09:17:28
合計ジャッジ時間 18,771 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,288 KB
testcase_01 AC 416 ms
83,264 KB
testcase_02 AC 548 ms
85,556 KB
testcase_03 AC 322 ms
80,612 KB
testcase_04 AC 823 ms
90,340 KB
testcase_05 AC 774 ms
84,272 KB
testcase_06 AC 1,583 ms
100,296 KB
testcase_07 AC 303 ms
78,920 KB
testcase_08 AC 779 ms
81,792 KB
testcase_09 AC 113 ms
77,388 KB
testcase_10 AC 818 ms
84,180 KB
testcase_11 AC 833 ms
84,080 KB
testcase_12 AC 856 ms
85,300 KB
testcase_13 AC 915 ms
82,796 KB
testcase_14 AC 734 ms
82,608 KB
testcase_15 AC 783 ms
90,704 KB
testcase_16 AC 811 ms
90,840 KB
testcase_17 AC 822 ms
91,768 KB
testcase_18 AC 747 ms
82,452 KB
testcase_19 AC 453 ms
80,196 KB
testcase_20 AC 183 ms
78,076 KB
testcase_21 AC 775 ms
88,692 KB
testcase_22 AC 647 ms
89,100 KB
testcase_23 AC 679 ms
90,692 KB
testcase_24 AC 489 ms
83,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def floor_sum(n,m,a,b):
    ans=0
    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
    ans+=floor_sum(y_max,a,m,(a-x_max%a)%a)
    return ans

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