結果
問題 | No.1358 [Zelkova 2nd Tune *] 語るなら枚数を... |
ユーザー |
![]() |
提出日時 | 2021-01-23 15:30:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 609 ms / 2,000 ms |
コード長 | 875 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 63,376 KB |
最終ジャッジ日時 | 2024-12-30 21:08:55 |
合計ジャッジ時間 | 4,748 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
import sysinput = sys.stdin.readlinemod=10**9+7from math import gcd# 拡張ユークリッドの互除法.ax+by=gcd(a,b)となる(x,y)を一つ求め、(x,y)とgcd(x,y)を返す.def Ext_Euc(a,b,axy=(1,0),bxy=(0,1)): # axy=a*1+b*0,bxy=a*0+b*1なので,a,bに対応する係数の初期値は(1,0),(0,1)# print(a,b,axy,bxy)q,r=divmod(a,b)if r==0:return bxy,b # a*bxy[0]+b*bxy[1]=brxy=(axy[0]-bxy[0]*q,axy[1]-bxy[1]*q) # rに対応する係数を求める.return Ext_Euc(b,r,bxy,rxy)T=int(input())for tests in range(T):N,K,H,Y=map(int,input().split())A=[N,K,H]A.sort(reverse=True)a,b,c=AG_bc=gcd(b,c)(x0,y0),G=Ext_Euc(b,c)ANS=0for i in range(Y//a+1):rest=Y-i*aif rest%G_bc!=0:continueANS+=rest*x0//c+rest*y0//b+1ANS%=modprint(ANS)