結果
| 問題 | No.2280 FizzBuzz Difference | 
| コンテスト | |
| ユーザー |  milanis48663220 | 
| 提出日時 | 2023-04-21 23:28:21 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 31 ms / 2,000 ms | 
| コード長 | 2,346 bytes | 
| コンパイル時間 | 1,104 ms | 
| コンパイル使用メモリ | 121,020 KB | 
| 最終ジャッジ日時 | 2025-02-12 12:35:29 | 
| ジャッジサーバーID (参考情報) | judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 7 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/math>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}
void solve(){
    ll m, a, b, k; cin >> m >> a >> b >> k;
    ll g = gcd(a, b);
    if(k%g != 0){
        cout << 0 << endl;
        return;
    }
    m /= g;
    a /= g;
    b /= g;
    k /= g;
    
    if(k > a){
        cout << 0 << endl;
        return;
    }
    ll l = a*b;
    ll iter = m/l;
    ll rem = m-(iter*l);
    if(k == a){
        // 頑張る...
        // aの倍数
        ll last_a = (m/a)*a;
        ll last_b = (m/b)*b;
        ll cnt_a = (m/a);
        ll cnt_b = (m/b);
        ll cnt_only_b = cnt_b-(m/(a*b));
        ll ans = cnt_a-1-cnt_only_b;
        if(last_b > last_a) ans++;
        cout << ans << endl;
        return;
    }
    ll ans = iter*2;
    // a-bのパターン
    {
        auto [r, lc] = atcoder::crt({0ll, k}, {a, b});
        if(r <= rem){
            ans++;
        }
    }
    // b-aのパターン
    {
        auto [r, lc] = atcoder::crt({0ll, k}, {b, a});
        if(r <= rem){
            ans++;
        }
    }
    cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
            
            
            
        