結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー titiatitia
提出日時 2021-01-23 15:30:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 596 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 76,512 KB
最終ジャッジ日時 2023-08-29 04:44:15
合計ジャッジ時間 5,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
76,080 KB
testcase_01 AC 71 ms
71,488 KB
testcase_02 AC 73 ms
71,228 KB
testcase_03 AC 72 ms
71,360 KB
testcase_04 AC 74 ms
71,500 KB
testcase_05 AC 75 ms
71,324 KB
testcase_06 AC 87 ms
76,512 KB
testcase_07 AC 84 ms
76,048 KB
testcase_08 AC 86 ms
76,096 KB
testcase_09 AC 87 ms
76,428 KB
testcase_10 AC 85 ms
76,256 KB
testcase_11 AC 550 ms
76,028 KB
testcase_12 AC 476 ms
76,220 KB
testcase_13 AC 596 ms
76,376 KB
testcase_14 AC 468 ms
76,408 KB
testcase_15 AC 500 ms
75,956 KB
testcase_16 AC 372 ms
76,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
mod=10**9+7
from 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]=b
   
    rxy=(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=A
    G_bc=gcd(b,c)
    (x0,y0),G=Ext_Euc(b,c)

    ANS=0

    for i in range(Y//a+1):
        rest=Y-i*a

        if rest%G_bc!=0:
            continue

        ANS+=rest*x0//c+rest*y0//b+1
        ANS%=mod


    print(ANS)
0