P1888 Trigonometric functions
Description
You are given a group of Pythagorean numbers of a, b, c(a!=b!=C). The sinusoidal value of its smaller acute angle is output in fractional format(a reduction is required).
Input format
The input is one line including three integral numbers of a, b, c.
Output format
one line includes a fraction that is its smaller acute angle's sinusoidal value.
Example
Input
3 5 4
Output
'3/5'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Coding
#include <iostream>
using namespace std;
long long gcd(long long a,long long b){
if(a==0)
return b;
gcd(b%a, a);
}
int tri() {
long long a,b,c,minn,maxn;
cin >> a >> b >> c;
minn=a;
if(b<minn) minn=b;
if(c<minn) minn=c;
maxn=a;
if(b>maxn) maxn=b;
if(c>maxn) maxn=c;
cout<< minn/gcd(minn,maxn) << '/' << maxn/gcd(minn,maxn);
return 0;
}
What I learned
How to compute the greatest common divisor?
Euclidean Algorithm:
- If we subtract smaller number from larger(we reduce larger number), GCD doesn't change. So if we keep subtracting repeatedly the larger of two, we end up with GCD.
- Now instead of subtraction, if we divide smaller number, the algorithm stops when we find remainder 0.
Proof: if a≡c (mod b), then (a,b) = (c,b).
if a≡c(mod b), then b|a−c, so there is a y such that a−c=by, i.e., c=a−by. If d divides both a and b, then it also divides a−by. Therefore any common divisor of a and b is also a common divisor of c and b. Similarly, if d divides both c and b, then it also divides c+by=a, so any common divisor of c and b is a common divisor of a and b. This shows that the common divisors of a and b are exactly the common divisors of c and b, so, in particular, they have the same greatest common divisor.