結果
問題 |
No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
|
ユーザー |
|
提出日時 | 2021-01-23 08:40:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,430 bytes |
コンパイル時間 | 1,102 ms |
コンパイル使用メモリ | 95,828 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-12-30 00:24:42 |
合計ジャッジ時間 | 18,985 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 5 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; long long const mod = 1000000007; long long gcd(long long a, long long b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } long long extGCD(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } int main(){ int t; cin >> t; for (int i = 0; i < t; i++) { long long n, k, h, y; long long a[3]; cin >> a[0] >> a[1] >> a[2] >> y; sort(a, a + 3); n = a[2], k = a[1], h = a[0]; long long ans = 0; for (int j = 0; j <= y / n; j++) { long long now = y - n * j; if (now % gcd(k, h) == 0) { long long K, H; extGCD(k, h, K, H); K *= now / gcd(k, h), H *= now / gcd(k, h); long long l = k * h / gcd(k, h); long long K1 = l / k; long long H1 = l / h; if (K < 0) { H -= (-K + K1 - 1) / K1 * H1; K += (-K + K1 - 1) / K1 * K1; } else if (H < 0) { K -= (-H + H1 - 1) / H1 * K1; H += (-H + H1 - 1) / H1 * H1; } if (K >= 0 && H >= 0) { ans += K / K1 + H / H1 + 1; ans %= mod; } } } cout << ans << endl; } }