Logo Wy Online Judge

WyOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#22#184#4. 「WyOJ Round 1」启 · 破茧初阳__vector__PigsyyFailed.2025-04-17 20:39:132025-04-17 20:39:14

Details

Extra Test:

Accepted
time: 3ms
memory: 3420kb

input:

1
114 514 1919 810

output:

0

result:

ok 1 number(s): "0"

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184#4. 「WyOJ Round 1」启 · 破茧初阳Pigsyy100912ms3492kbC++14659b2025-04-17 20:34:372025-04-17 20:40:53

answer

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

typedef long long LL;

int lcm(int a, int b) {
    return a / __gcd(a, b) * b;
}

void solve() {
    int n, a ,b, c;
    cin >> n >> a >> b >> c;

    int res = n / a - n / lcm(a, b) + n / c - n / lcm(a, c);
    int temp = lcm(lcm(a, b), c);
	 if (temp % a == 0 && temp % b == 0 && temp % c == 0) res += n / temp, assert(temp >= 0);
    cout << res << '\n';
}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int dt;
    cin >> dt;

    while (dt --)
        solve();

    return 0;
}