/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 500.0 KiB
#2 Accepted 10ms 616.0 KiB
#3 Accepted 10ms 620.0 KiB
#4 Accepted 9ms 600.0 KiB
#5 Accepted 8ms 568.0 KiB
#6 Accepted 8ms 568.0 KiB
#7 Accepted 8ms 580.0 KiB
#8 Accepted 7ms 576.0 KiB
#9 Accepted 9ms 612.0 KiB
#10 Accepted 9ms 596.0 KiB

Code

#include <bits/stdc++.h>
#include <math.h>
 
using namespace std;
 
// Macros
#define REP(i, j, n) for(int i = j; i < n; i++)
#define trav(i, a) for(auto i: a)
#define all(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define GCD __gcd
 
// Type Names
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

// custom hash
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	vi v{a, b, c};
	sort(all(v));
	a = v[0];
	b = v[1];
	c = v[2];
	int dif1 = abs(a - b);
	int dif2 = abs(b - c);
	if (dif1 == 0 && dif2 == 0){
		cout << 0 << "\n";
	}
	else if (dif1 == 0 || dif2 == 0){
		cout << 1 << "\n";
	}
	else {
		cout << (dif1 + dif2) / GCD(dif1, dif2) << "\n";
	}
}

 
int main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1061 Bring equality
Contest
Brain Booster #4
Language
C++17 (G++ 13.2.0)
Submit At
2024-07-14 15:54:30
Judged At
2024-10-03 13:39:02
Judged By
Score
100
Total Time
10ms
Peak Memory
620.0 KiB