/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 1ms 764.0 KiB
#3 Accepted 2ms 764.0 KiB
#4 Accepted 2ms 764.0 KiB
#5 Accepted 2ms 536.0 KiB
#6 Accepted 5ms 764.0 KiB
#7 Accepted 5ms 764.0 KiB
#8 Accepted 5ms 556.0 KiB
#9 Accepted 5ms 552.0 KiB
#10 Accepted 5ms 532.0 KiB
#11 Accepted 4ms 532.0 KiB
#12 Accepted 5ms 764.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
    while (b != 0) {
        long long temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}
long long lcm(long long a, long long b) {
    return (a / gcd(a, b)) * b;
}
long long gcm(long long a, long long b, long long c, long long X) {


    long long labc = lcm(lcm(a, b), c);

    if (labc >= X) {
        return -1;
    }
    long long mult = (X - 1) / labc;
    return labc * mult;
}
int main() {
    int t;
    cin >> t;

    while (t--) {
        long long a, b, c, X;
        cin >> a >> b >> c >> X;

        long long result = gcm(a, b, c, X);

        cout << result << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1025 GCM
Contest
Brain booster #2
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-06 13:55:42
Judged At
2024-11-11 03:42:08
Judged By
Score
100
Total Time
5ms
Peak Memory
764.0 KiB