結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-23 03:42:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 729 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 86,500 KB
実行使用メモリ 76,300 KB
最終ジャッジ日時 2023-08-28 13:45:25
合計ジャッジ時間 5,619 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,860 KB
testcase_01 AC 71 ms
71,116 KB
testcase_02 AC 71 ms
71,148 KB
testcase_03 AC 72 ms
71,400 KB
testcase_04 AC 71 ms
71,316 KB
testcase_05 AC 70 ms
71,080 KB
testcase_06 AC 85 ms
75,956 KB
testcase_07 AC 84 ms
76,156 KB
testcase_08 AC 87 ms
75,912 KB
testcase_09 AC 87 ms
76,284 KB
testcase_10 AC 84 ms
76,072 KB
testcase_11 AC 625 ms
76,300 KB
testcase_12 AC 597 ms
75,940 KB
testcase_13 AC 729 ms
76,084 KB
testcase_14 AC 527 ms
76,060 KB
testcase_15 AC 569 ms
75,900 KB
testcase_16 AC 422 ms
76,148 KB
権限があれば一括ダウンロードができます

ソースコード

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())
    n, k, h = sorted([n, k, h], reverse=True)
    g = math.gcd(k, h)
    a, b = k//g, h//g
    x0, y0, _ = extgcd(a, b)
    ans = 0
    for i in range(y//n+1):
        c = y-n*i
        if c%g:
            continue
        c = c//g
        ans += (c*y0)//a-(-c*x0+b-1)//b+1
        ans %= mod
    print(ans)
0