結果
問題 | No.1358 [Zelkova 2nd Tune *] 語るなら枚数を... |
ユーザー | persimmon-persimmon |
提出日時 | 2021-02-13 20:29:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,489 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 87,160 KB |
実行使用メモリ | 77,172 KB |
最終ジャッジ日時 | 2023-08-17 03:02:10 |
合計ジャッジ時間 | 11,930 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
76,084 KB |
testcase_01 | AC | 71 ms
71,020 KB |
testcase_02 | AC | 73 ms
71,212 KB |
testcase_03 | AC | 72 ms
71,192 KB |
testcase_04 | AC | 74 ms
71,384 KB |
testcase_05 | AC | 74 ms
71,428 KB |
testcase_06 | AC | 118 ms
76,640 KB |
testcase_07 | AC | 107 ms
76,772 KB |
testcase_08 | AC | 104 ms
76,796 KB |
testcase_09 | AC | 107 ms
76,828 KB |
testcase_10 | AC | 106 ms
76,552 KB |
testcase_11 | AC | 1,708 ms
77,144 KB |
testcase_12 | AC | 1,735 ms
76,904 KB |
testcase_13 | TLE | - |
testcase_14 | AC | 1,374 ms
76,772 KB |
testcase_15 | AC | 1,640 ms
76,652 KB |
testcase_16 | AC | 885 ms
76,756 KB |
ソースコード
mod=10**9+7 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 a, x0, y0 memo={} def modinv(a, m): if (a,m) in memo:return memo[(a,m)] g, x, y = xgcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: memo[(a,m)]=x%m return x % m def main1(n,k,h,y): ary=[n,k,h] ary.sort() a,b,c=ary g=gcd(a,b) na,nb=a//g,b//g now=0 ans=0 while now<=y: yy=y-now now+=c if yy%g!=0:continue yy=yy//g if yy==0: ans+=1 continue if yy<na:continue if yy<nb: if yy%na==0: ans+=1 continue # yy-nb*iがmod naで0になるiの個数 # yy%na=nb*i%na となるiの個数 # 0<=i<=yy//nb # yy%na=nb*i%na となる最小のiを求める。あとは周期naで循環する。 u=yy%na v=nb%na # u=v*i # u*v^(-1)=i if u==0: i=0 elif u==v: i=1 else: i=u*modinv(v,na) i%=na #print((na,nb),yy,i) if yy-nb*i<0:continue w=yy//nb if i<=w: ans+=(w-i)//na+1 ans%=mod #print((u,v,w)) #print((na,nb,yy),i,w,(w-i)//na+1) return ans import sys input=sys.stdin.readline if __name__=='__main__': t=int(input()) cases=[list(map(int,input().split())) for _ in range(t)] for n,k,h,y in cases: print(main1(n,k,h,y))