結果
問題 | No.1358 [Zelkova 2nd Tune *] 語るなら枚数を... |
ユーザー |
![]() |
提出日時 | 2024-02-23 05:23:45 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 378 ms / 2,000 ms |
コード長 | 1,400 bytes |
コンパイル時間 | 1,408 ms |
コンパイル使用メモリ | 127,344 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-29 04:47:36 |
合計ジャッジ時間 | 3,851 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <array>#include <iterator>#include <string>#include <cctype>#include <cstring>#include <cstdlib>#include <cassert>#include <cmath>#include <ctime>#include <iomanip>#include <numeric>#include <stack>#include <queue>#include <map>#include <unordered_map>#include <set>#include <unordered_set>#include <bitset>#include <random>#include <utility>#include <functional>using namespace std;long long gcd(long long a,long long b,long long &x,long long &y){x = 1,y = 0;long long z = 0,w = 1;while(b){long long q = a / b;a -= q * b; swap(a,b);x -= q * z; swap(x,z);y -= q * w; swap(y,w);}return a;}void Main(){long long a,b,c,Y;cin >> a >> b >> c >> Y;if(a < b){swap(a,b);}if(a < c){swap(a,c);}long long y,z;long long g = gcd(b,c,y,z);b /= g,c /= g;const int mod = (int)1e9 + 7;long long ans = 0;for(int i = 0;a * i <= Y;i++){long long Z = Y - a * i;if(Z % g){continue;}long long p = y * (Z / g),q = z * (Z / g);//b * p + c * q == Zq = -q;long long L = q >= 0 ? (q + b - 1) / b : -((-q) / b);long long U = p >= 0 ? p / c : -((-p + c - 1) / c);ans += max(0ll,U - L + 1);ans %= mod;}cout << ans << "\n";}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int tt = 1;cin >> tt;while(tt--) Main();}