結果
問題 |
No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
|
ユーザー |
![]() |
提出日時 | 2021-01-22 23:52:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 793 bytes |
コンパイル時間 | 4,087 ms |
コンパイル使用メモリ | 193,572 KB |
最終ジャッジ日時 | 2025-01-18 06:38:33 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 12 TLE * 5 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; ll extGCD(ll a,ll b,ll &x,ll &y){ if(b==0){ x=1; y=0; return a; } ll d=extGCD(b,a%b,y,x); y-=a/b*x; return d; } int main(){ int t; cin>>t; while(t--){ ll n,k,h,y; cin>>n>>k>>h>>y; if(n>h) swap(n,h); if(k>h) swap(k,h); if(n>k) swap(n,k); ll ans=0; for(int i=0;i<=y/h;i++){ ll r=(y-h*i)/gcd(n,k); ll a=n/gcd(n,k); ll b=k/gcd(n,k); ll p,q; if(extGCD(a,b,p,q)<0) p=-p,q=-q; p*=r,q*=r; if(q/a<-p/b) continue; ans=(ans+p/b+q/a)%MOD; if(p%b==0) ans++; } cout<<ans<<endl; } return 0; }