結果

問題 No.2280 FizzBuzz Difference
ユーザー milanis48663220milanis48663220
提出日時 2023-04-21 23:19:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,469 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 123,172 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:18:35
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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 > b) {
        cout << 0 << endl;
        return;
    }
    if(k == b){
        cout << 0 << endl;
        return;
    }
    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)*a;
        ll cnt_a = (m/a);
        ll cnt_b = (m/b);
        ll cnt_only_b = cnt_b-(m/(a*b));
        ll ans = m/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();
}
0