結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー titiatitia
提出日時 2021-01-23 14:57:21
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 81,316 KB
最終ジャッジ日時 2023-08-29 01:51:27
合計ジャッジ時間 5,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
76,476 KB
testcase_01 AC 70 ms
71,456 KB
testcase_02 AC 70 ms
71,184 KB
testcase_03 AC 71 ms
71,380 KB
testcase_04 AC 71 ms
71,176 KB
testcase_05 AC 70 ms
71,384 KB
testcase_06 AC 90 ms
76,260 KB
testcase_07 AC 91 ms
76,276 KB
testcase_08 AC 96 ms
76,012 KB
testcase_09 AC 93 ms
76,180 KB
testcase_10 AC 91 ms
76,184 KB
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
        elif (-b*x0)<=0 and (c*y0)<=0:
            ANS+=abs(abs(-b*x1)//L-(abs(c*y1)-1)//L)
        else:
            ANS+=abs((abs(c*y1))//L-(abs(-b*x1)-1)//L)
            
        ANS%=mod


    print(ANS)
        

        
        
        

        
        
        
    

0