結果
問題 |
No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
|
ユーザー |
|
提出日時 | 2021-01-23 19:18:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,385 bytes |
コンパイル時間 | 1,665 ms |
コンパイル使用メモリ | 194,104 KB |
最終ジャッジ日時 | 2025-01-18 07:37:42 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 11 TLE * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; int extGCD(int a, int b, int &x, int &y) { if (b==0) { x = 1; y = 0; return a; } int d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } signed main() { int T; cin >> T; int x, y; while (T--) { int N, K, H, Y; cin >> N >> K >> H >> Y; int M = max({N, K, H}); int c = Y/M; int ans = 0; for (int i=0; i<=c; i++) { int nokori = Y-i*M; if (M==N) { int G = extGCD(K, H, x, y); if (nokori%G==0) { x *= nokori/G; y *= nokori/G; ans += y/K-(-x+H-1)/H+1; } } else if (M==K) { int G = extGCD(H, N, x, y); if (nokori%G==0) { x *= nokori/G; y *= nokori/G; ans += y/H-(-x+N-1)/N+1; } } else { int G = extGCD(N, K, x, y); if (nokori%G==0) { x *= nokori/G; y *= nokori/G; ans += y/N-(-x+K-1)/K+1; } } ans %= MOD; } cout << ans << endl; } }