結果

問題 No.2280 FizzBuzz Difference
ユーザー 沙耶花沙耶花
提出日時 2023-04-21 23:00:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 4,623 ms
コンパイル使用メモリ 254,388 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:01:55
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 8000000000000000001

long long get(long long M,long long A,long long B,long long K){
	long long ans = 0;
	if(A<K){
	}
	else if(A==K){
		ans = (M/A)-1 - ((M/A)*A/B);
		ans += M / lcm(A,B);
	}
	else{
		rep(__,2){
			swap(A,B);
			auto ret = crt({0,K},{A,B});
			if(ret.second!=0){
				long long left = 0,right = Inf64;
				long long b = ret.second;
				long long a = ret.first;
			//	cout<<a<<','<<b<<endl;
				if(A-a+b-1<0||B+K-a+b-1<0)continue;
				if(M-a<0)continue;
				left = max({left,(A-a+b-1)/b,(B+K-a+b-1)/b});
				right = min({right,(M-a)/b,(M-a+K)/b});
				ans += max(0LL,right-left+1);
			//	cout<<left<<','<<right<<endl;
			}
			
		}
	}
	return ans;
}

long long gu(long long M,long long A,long long B,long long K){
	long long ret = 0;
	long long last = -Inf64;
	for(long long i=1;i<=M;i++){
		if(i%A==0||i%B==0){
			if(i-last==K)ret++;
			last = i;
		}
	}
	return ret;
}
int main(){
	/*
	for(int i=1;i<=10;i++){
		for(int j=1;j<=i;j++){
			for(int k=j+1;k<=10;k++){
				for(int l=1;l<=10;l++){
					if(get(i,j,k,l)!=gu(i,j,k,l)){
						cout<<i<<','<<j<<','<<k<<','<<l<<endl;
						cout<<get(i,j,k,l)<<','<<gu(i,j,k,l)<<endl;
						return 0;
					}
				}
			}
		}
	}
	
	*/
	int _t;
	cin>>_t;
	rep(_,_t){
		
		long long M,A,B,K;
		cin>>M>>A>>B>>K;
		cout<<get(M,A,B,K)<<endl;
		//cout<<gu(M,A,B,K)<<endl;
	}
	
	return 0;
}
0