結果

問題 No.2280 FizzBuzz Difference
ユーザー kotatsugamekotatsugame
提出日時 2023-04-21 23:12:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 826 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 77,236 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 09:12:51
合計ジャッジ時間 1,168 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 13 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 15 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#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 lcm=(long long)A*B;
			long long ans=M/lcm*(B-A+1);
			M%=lcm;
			ans+=M/A-M/B;
			if(ans)ans--;
			cout<<ans<<"\n";
			continue;
		}
		long long ans=0;
		for(int t=0;t<2;t++,swap(A,B))
		{//iA=-K mod B
			int 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";
	}
}
0