結果

問題 No.2280 FizzBuzz Difference
ユーザー magsta
提出日時 2023-04-18 16:09:54
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,702 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 62,356 KB
最終ジャッジ日時 2025-02-12 09:57:05
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:2:10: fatal error: testlib.h: No such file or directory
    2 | #include "testlib.h"
      |          ^~~~~~~~~~~
compilation terminated.

ソースコード

diff #

#include <bits/stdc++.h>
#include "testlib.h"
using namespace std;

long long modinv(long long a, long long mod) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

int main() {
	registerValidation();
    int T = inf.readInt(1, 10000, "T");
    inf.readEoln();
    for (int i = 0; i < T; i++) {
        long long M, A, B, K;
        M = inf.readLong(1LL, 1000000000000000000LL, "M");
        inf.readSpace();
        A = inf.readLong(1LL, min(M, 1000000000LL), "A");
        inf.readSpace();
        B = inf.readLong(A + 1, 1000000000LL, "B");
        inf.readSpace();
        K = inf.readLong(1LL, 1000000000LL, "K");
        inf.readEoln();
        long long Gcd = gcd(A, B);
        if (K % Gcd != 0) {
            cout << 0 << endl;
            continue;
        }
        else {
            A /= Gcd;
            B /= Gcd;
            K /= Gcd;
            M /= Gcd;
        }
        if (K < A) {
            long long ans = (M / (A * B)) * 2;
            long long a = (K * modinv(B, A)) % A;
            long long b = A - a;
            if (B * a + (M / (A * B)) * A * B <= M) ans++;
            if (B * b + (M / (A * B)) * A * B + K <= M) ans++;
            cout << ans << endl;
        }
        else if (K == A) {
            long long ans = M / A + M / B - M / (A * B) - 1;
            if ((M / A) * A >= (M / B) * B) ans -= 2 * (M / B - M / (A * B));
            else ans -= 2 * (M / B - M / (A * B)) - 1;
            cout << ans << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    inf.readEof();
}
0