結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-13 20:50:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 76,476 KB
最終ジャッジ日時 2023-09-28 06:14:34
合計ジャッジ時間 5,659 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
76,412 KB
testcase_01 AC 68 ms
71,508 KB
testcase_02 AC 69 ms
71,324 KB
testcase_03 AC 68 ms
71,424 KB
testcase_04 AC 70 ms
71,320 KB
testcase_05 AC 72 ms
71,548 KB
testcase_06 AC 85 ms
76,328 KB
testcase_07 AC 83 ms
76,376 KB
testcase_08 AC 87 ms
76,344 KB
testcase_09 AC 88 ms
76,312 KB
testcase_10 AC 86 ms
76,380 KB
testcase_11 AC 648 ms
76,344 KB
testcase_12 AC 617 ms
76,476 KB
testcase_13 AC 736 ms
76,344 KB
testcase_14 AC 538 ms
76,156 KB
testcase_15 AC 579 ms
76,332 KB
testcase_16 AC 589 ms
76,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


def main0(n,k,h,y):
  a,b=0,0
  ans=0
  while a<=y:
    b=0
    while a+b<=y:
      yy=y-a-b
      if yy%h==0:
        ans+=1
      b+=k
    a+=n
  return ans

def gcd(a,b):
  while b:a,b=b,a%b
  return a

def xgcd(a, b):
    x0, y0, x1,y1=1,0,0,1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return x0
memo={}
def modinv(a, m):
    if (a,m) in memo:return memo[(a,m)]
    x=xgcd(a, m)
    memo[(a,m)]=x%m
    return x % m

def ext_gcd(a, b):  # a*x+b*y==gcd(a,b)たるgcd(a,b),x,y
  if b > 0:
    d,x,y = ext_gcd(b,a % b)
    return d,y,x-(a//b)*y
  return a,1,0

import sys
input=sys.stdin.readline
t=int(input())
cases=[list(map(int,input().split())) for _ in range(t)]
mod=10**9+7
for n,k,h,y in cases:
  ary=[n,k,h]
  ary.sort()
  k,h,n=ary
  g,a,b=ext_gcd(k,h)
  k,h=k//g,h//g
  ans=0
  for i in range(y//n+1):
    z=y-i*n
    if z%g!=0:continue
    z//=g
    # k*u+h*v=z の解の個数
    c,d=a*z,b*z
    ans+=max(1+d//k-(-c+h-1)//h,0)
    ans%=mod
  print(ans)
0