Cavets:
The most difficult part of it is the fraction reduction process, that is, finding the greatest common divisor(gcd) of the numerator and denominator, and then dividing them using the gcd.
Euclidean algorithm: Find the gcd!
Basic idea: larger mod smaller get the remainder, if remainder isn’t 0, then using smaller mod remainder and so forth.
When the remainder equals 0, the divisor is the gcd.
Code:
while (lar % sma != 0) {
int tmp = lar % sma;
lar = sma;
sma = tmp;
}
int gcd = sma;
https://zh.wikipedia.org/wiki/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95