-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path337B-Routine.cpp
55 lines (44 loc) · 1 KB
/
337B-Routine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<set>
#include<climits>
using namespace std;
#define ll long long
inline ll nxt()
{
ll x;
cin >> x;
return x;
}
ll GCD(ll a, ll b)
{
if (a == 0)
return b;
return GCD(b % a, a);
}
int main(){
pair<ll,ll> a = {nxt(),nxt()};
pair<ll,ll> b = {nxt(),nxt()};
// Check horizontal
ll num = a.first;
ll den = b.first;
double val = (double)num/(double)den;
if(a.second >= (val)*b.second){
ll numf = a.first*a.second*den - a.first*a.first*b.second;
ll denf = a.first*a.second*den;
ll gcd = GCD(numf,denf);
cout<<(numf/gcd)<<"/"<<(denf/gcd);
return 0;
}
// check vertical
num = a.second;
den = b.second;
val = (double)num/(double)den;
ll numf = a.first*a.second*den - a.second*a.second*b.first;
ll denf = a.first*a.second*den;
ll gcd = GCD(numf,denf);
cout<<(numf/gcd)<<"/"<<(denf/gcd);
return 0;
}