結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-22 22:41:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 80,440 KB
最終ジャッジ日時 2023-08-27 20:44:01
合計ジャッジ時間 7,175 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,500 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 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = sys.stdin.buffer.readline

t = int(input())
mod = 10**9+7

def extgcd(a, b):
    # ax+by = gcd(x, y)の整数解を求める
    # x, y, gcd(a, b)を返す
    if b == 0:
        return 1, 0, a
    q, r = divmod(a, b)
    x, y, d = extgcd(b, r)
    s, t = y, x-q*y
    return s, t, d

for _ in range(t):
    n, k, h, y = map(int, input().split())
    a0, b0, g = extgcd(n, k)
    #print(a0, b0)
    ans = 0
    for c in range(y//h+1):
        if (y-h*c)%g == 0:
            p = (y-h*c)//g
            cnt = max((p*b0)//n-(-p*a0+k-1)//k+1, 0)
        else:
            cnt = 0
        ans += cnt
        ans %= mod
    print(ans)
0