結果

問題 No.2280 FizzBuzz Difference
ユーザー kotatsugamekotatsugame
提出日時 2023-04-24 17:38:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 77,980 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 05:42:06
合計ジャッジ時間 1,788 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 12 ms
6,940 KB
testcase_02 AC 15 ms
6,940 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 AC 17 ms
6,944 KB
testcase_05 AC 12 ms
6,944 KB
testcase_06 AC 13 ms
6,940 KB
testcase_07 AC 14 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 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