/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 524.0 KiB
#2 Accepted 29ms 548.0 KiB
#3 Accepted 29ms 560.0 KiB
#4 Accepted 29ms 596.0 KiB
#5 Accepted 27ms 588.0 KiB
#6 Accepted 29ms 552.0 KiB
#7 Accepted 28ms 556.0 KiB
#8 Accepted 27ms 340.0 KiB
#9 Accepted 29ms 604.0 KiB
#10 Accepted 29ms 560.0 KiB

Code

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

#define ll long long
#define endl '\n'

int main()
{   
    
    int t; cin >> t;
    while(t--) {
        int arr[4];
        for (int i = 0; i < 3; i++) {
            cin >> arr[i];
        }
        int diff[4];
        diff[0] = abs(arr[0] - arr[1]);
        diff[1] = abs(arr[1] - arr[2]);
        diff[2] = abs(arr[2] - arr[0]);       
        int cut = 0;
        for (int i = 0; i < 3; i++) {
            cut = __gcd(cut,diff[i]);
        }

        if (cut == 0) cout << 0 << endl;
        else{
            sort(arr+0,arr+3);

            ll ans = 0;
            ans += (arr[1] - arr[0]) / cut;
            ans += (arr[2] - arr[1]) / cut;
            cout << ans << 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 17:58:45
Judged At
2024-11-11 03:22:32
Judged By
Score
100
Total Time
29ms
Peak Memory
604.0 KiB