結果
| 問題 | No.2280 FizzBuzz Difference | 
| コンテスト | |
| ユーザー |  沙耶花 | 
| 提出日時 | 2023-04-21 23:00:01 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 46 ms / 2,000 ms | 
| コード長 | 1,562 bytes | 
| コンパイル時間 | 4,132 ms | 
| コンパイル使用メモリ | 252,568 KB | 
| 最終ジャッジ日時 | 2025-02-12 12:24:47 | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 7 | 
ソースコード
#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;
}
            
            
            
        