/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 7ms 580.0 KiB
#3 Accepted 7ms 580.0 KiB
#4 Accepted 7ms 596.0 KiB
#5 Accepted 6ms 580.0 KiB
#6 Accepted 4ms 576.0 KiB
#7 Accepted 4ms 564.0 KiB
#8 Accepted 4ms 580.0 KiB
#9 Accepted 8ms 600.0 KiB
#10 Accepted 8ms 616.0 KiB

Code

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

void solve() {
	int arr[3];
	for (int i = 0; i < 3; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + 3);
	int gc = arr[2] - arr[0];
	gc = gcd(arr[2] - arr[0], gc);
	gc = gcd(arr[2] - arr[1], gc);
	if (gc == 0) {
		cout << "0\n";
		return;
	}

	auto get = [&](int a, int b, int c) {
		int gc = abs(c - a);
		gc = gcd(gc, abs(c - b));
		// cout << gc << " ";
		return abs(c - a) / gc + abs(c - b) / gc;
	};
	int ans = get(arr[0], arr[1], arr[2]);
	// cout << ans << "\n";
	ans = min(ans, get(arr[2], arr[0], arr[1]));
	// cout << ans << "\n";
	ans = min(ans, get(arr[2], arr[1], arr[0]));
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int tt = 1;
	cin >> tt;
	while (tt--) {
		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:49:03
Judged At
2024-10-03 13:36:50
Judged By
Score
100
Total Time
8ms
Peak Memory
616.0 KiB