結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー 👑 KazunKazun
提出日時 2020-09-09 16:14:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 856 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 78,944 KB
最終ジャッジ日時 2023-09-30 18:13:39
合計ジャッジ時間 3,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

N,K,H,Y=map(int,input().split())
assert 1<=N<=10**7,"Nが制約違反(N={})".format(N)
assert 1<=K<=10**7,"Kが制約違反(N={})".format(K)
assert 1<=H<=10**7,"Hが制約違反(N={})".format(H)
assert min(Y//N,Y//K,Y//H)<=10**7,"計算量が多すぎ(N={},K={},H={},Y={})".format(N,K,H,Y)


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

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

    S=beta//g

    p,q,_=f(A,B)

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

    Ans+=upper-lower+1
    Ans%=Mod

print(Ans)
0