結果
問題 | No.1358 [Zelkova 2nd Tune *] 語るなら枚数を... |
ユーザー | rlangevin |
提出日時 | 2023-05-28 16:15:03 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 817 bytes |
コンパイル時間 | 445 ms |
コンパイル使用メモリ | 86,864 KB |
実行使用メモリ | 82,980 KB |
最終ジャッジ日時 | 2023-08-27 13:49:20 |
合計ジャッジ時間 | 6,169 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 113 ms
81,288 KB |
testcase_01 | AC | 88 ms
75,592 KB |
testcase_02 | AC | 87 ms
75,692 KB |
testcase_03 | AC | 80 ms
75,620 KB |
testcase_04 | AC | 83 ms
75,616 KB |
testcase_05 | AC | 85 ms
75,756 KB |
testcase_06 | AC | 180 ms
77,780 KB |
testcase_07 | AC | 156 ms
77,584 KB |
testcase_08 | AC | 224 ms
78,880 KB |
testcase_09 | AC | 181 ms
78,140 KB |
testcase_10 | AC | 217 ms
79,112 KB |
testcase_11 | TLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
ソースコード
import sys input = sys.stdin.readline from math import gcd def extGCD(a, b): # ax + by = gcd(a, b)の解を求める if b == 0: return 1, 0 q = a // b r = a % b X, Y = extGCD(b, r) return Y, X - q * Y T = int(input()) mod = 10**9 + 7 for _ in range(T): N, K, H, Y = map(int, input().split()) A = [N, K, H] A.sort() g = gcd(A[0], A[1]) ans = 0 for i in range(10 ** 6 + 5): C = Y - i * A[-1] if C < 0: break if C % g != 0: continue c = C // g n, k = A[0]//g, A[1]//g p, q = extGCD(n, k) ma = c * q // n mi = (-c * p + k - 1)//k ans += max(0, (ma - mi) + 1) ans %= mod # print("test", i, p, q, C, g) print(ans)