結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-23 03:27:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 789 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 76,480 KB
最終ジャッジ日時 2023-08-28 13:31:48
合計ジャッジ時間 7,075 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
76,048 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 WA -
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

import math

for _ in range(t):
    n, k, h, y = map(int, input().split())
    G = math.gcd(n, math.gcd(k, h))
    if y%G:
        print(0)
        continue
    n, k, h, y = n//G, k//G, h//G, y//G
    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 = (p*b0)//n-(-p*a0+k-1)//k+1
        else:
            cnt = 0
        ans += cnt
        ans %= mod
    print(ans)
0