結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー titiatitia
提出日時 2021-01-23 14:54:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,137 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 8,488 KB
最終ジャッジ日時 2023-08-29 01:48:45
合計ジャッジ時間 5,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
8,332 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
    L=b*c//G_bc

    ANS=0

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

        if rest%G_bc!=0:
            continue

        x1=x0*rest//G_bc
        y1=y0*rest//G_bc

        #print(-b*x1,c*y1)

        if (-b*x0)*(c*y0)<=0:
            ANS+=b*x1//L+c*y1//L+1
        else:
            ANS+=abs(abs(-b*x1)//L-(abs(c*y1)-1)//L)
        ANS%=mod


    print(ANS)
        

        
        
        

        
        
        
    

0