結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー 👑 KazunKazun
提出日時 2020-10-24 02:08:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 718 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 76,436 KB
最終ジャッジ日時 2023-09-30 18:15:47
合計ジャッジ時間 5,641 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,108 KB
testcase_01 AC 79 ms
71,304 KB
testcase_02 AC 79 ms
71,344 KB
testcase_03 AC 79 ms
71,336 KB
testcase_04 AC 79 ms
71,604 KB
testcase_05 AC 81 ms
71,388 KB
testcase_06 AC 97 ms
76,228 KB
testcase_07 AC 92 ms
76,164 KB
testcase_08 AC 93 ms
76,256 KB
testcase_09 AC 93 ms
76,168 KB
testcase_10 AC 95 ms
76,396 KB
testcase_11 AC 649 ms
76,180 KB
testcase_12 AC 597 ms
76,192 KB
testcase_13 AC 718 ms
76,400 KB
testcase_14 AC 546 ms
76,248 KB
testcase_15 AC 580 ms
76,156 KB
testcase_16 AC 427 ms
76,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(a, b):
    """
    ax + by = gcd(a,b) = d となる (x,y,d) を返す
    """
    if b == 0:
        return (1, 0, a)
    q, r = a // b, a % b
    x, y, d = f(b, r)
    s, t = y, x - q * y
    return s, t, d
#================================================
from math import gcd

T=int(input())
for _ in range(T):
    N,K,H,Y=map(int,input().split())

    N,K,H=sorted([N,K,H],reverse=True)
    Mod=10**9+7
    Ans=0
    g=gcd(K,H)
    A,B=K//g,H//g
    p,q,_=f(A,B)

    for x in range(0,Y//N+1):
        beta=Y-N*x
        if beta%g:
            continue

        S=beta//g

        upper=S*q//A
        lower=(-S*p+(B-1))//B

        Ans+=upper-lower+1
        Ans%=Mod
    print(Ans)
0