/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 6ms 600.0 KiB
#3 Accepted 6ms 620.0 KiB
#4 Accepted 6ms 612.0 KiB
#5 Accepted 5ms 576.0 KiB
#6 Accepted 4ms 580.0 KiB
#7 Accepted 4ms 576.0 KiB
#8 Accepted 4ms 572.0 KiB
#9 Accepted 6ms 576.0 KiB
#10 Accepted 6ms 588.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define lld long long double
#define ull unsigned long long

void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    vector <ll> lst = {a,b,c};
    sort(lst.begin(), lst.end());
    if (a == b && b == c){
        cout << 0 << endl;
    }
    else if (a == b || b == c || a == c){
        cout << 1 << endl;
    }
    else{
        ll dif1 = lst[1] - lst[0];
        ll dif2 = lst[2] - lst[1];

        if (dif1 == dif2){
            cout << 2 << endl;
        }
        else{
            ll sol = __gcd(dif1, dif2);
            ll ans = (dif1+dif2) / sol;

            cout << ans << endl; 
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1061 Bring equality
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 16:50:41
Judged At
2024-10-03 13:36:47
Judged By
Score
100
Total Time
6ms
Peak Memory
620.0 KiB