結果
問題 | No.2280 FizzBuzz Difference |
ユーザー |
|
提出日時 | 2023-04-24 17:38:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 1,074 ms |
コンパイル使用メモリ | 76,720 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 18:29:37 |
合計ジャッジ時間 | 2,313 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 |
ソースコード
#include<iostream>#include<cassert>#include<atcoder/math>using namespace std;int gcd(int a,int b){while(b){int t=a%b;a=b;b=t;}return a;}long long M;int A,B,K;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin>>T;for(;T--;){cin>>M>>A>>B>>K;if(A<K){cout<<"0\n";continue;}int g=gcd(A,B);if(K%g!=0){cout<<"0\n";continue;}A/=g;B/=g;K/=g;M/=g;if(K==A){long long ans=M/A-(M/A*A)/B-1;ans+=M/A/B;cout<<ans<<"\n";continue;}long long ans=0;for(int t=0;t<2;t++,swap(A,B)){//iA=-K mod Bint i=(long long)-K*atcoder::inv_mod(A,B)%B;if(i<0)i+=B;if(M>=K){long long lim=(M-K)/A-i;if(lim>=0)ans+=lim/B+1;}}cout<<ans<<"\n";}}