/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 9ms 580.0 KiB
#3 Accepted 9ms 608.0 KiB
#4 Accepted 9ms 576.0 KiB
#5 Accepted 7ms 532.0 KiB
#6 Accepted 4ms 536.0 KiB
#7 Accepted 4ms 536.0 KiB
#8 Accepted 4ms 764.0 KiB
#9 Accepted 9ms 600.0 KiB
#10 Accepted 9ms 600.0 KiB

Code


/* Two Roads Diverged in a Wood, and I Took the One  Less Travelled by,and That Has Made all the Difference */

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

#define endl '\n'
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front

#define yes1 cout << "YES\n"
#define yes2 cout << "Yes\n"
#define no1 cout << "NO\n"
#define no2 cout << "No\n"

#define mod1 1000000007
#define mod2 998244353
#define pi 3.141592653589793238462643383279502884197

#define __lcm(a, b) ((a / __gcd(a, b)) * b)

// ans<0 (ans+mod)%mod
//(a/b)%mod=a*(b^MOD-2)

// void std_in_out() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }

void solve()
{
    int a[3];
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    sort(a, a + 3);
    if (a[0] == a[2])
        cout << 0 << endl;
    else if (a[0] == a[1] || a[1] == a[2])
        cout << 1 << endl;
    else
    {
        int ans = 1e9;
        for (int j = 0; j < 3; j++)
        {
            vector<int> v;
            for (int i = 0; i < 3; i++)
            {
                if (i != j)
                 v.pb(abs(a[j] - a[i]));
            }
            // for(auto u:v) cout << u << " ";
            // cout << endl;   
            int gcd = 0;
            for (auto u : v)
                gcd = __gcd(gcd, u);
            int check = 0;
            for (auto u : v)
                check += u / gcd;
            ans = min(ans, check);
        }
        cout << ans << endl;
    }
}
int32_t main()
{

    ios_base ::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //   std_in_out()
    int tc, t = 0;
    tc = 1;
    cin >> tc;
    while (tc--)
    {
        // auto st = clock();
        //  cout<<"Case "<<++t<<": ";
        solve();
        // cerr << 1.0 * (clock() - st) / CLOCKS_PER_SEC << endl;
    }
    return 0;
}

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:51:41
Judged At
2024-10-03 13:36:46
Judged By
Score
100
Total Time
9ms
Peak Memory
764.0 KiB