Problem 5: Joint Attack
https://open.kattis.com/problems/jointattack
Start at the inner-most fraction, and evaluate outward. To output a fraction, keep track of the numerator and denominator using a long long
while evaluating.
You must simplify the fraction at each step to avoid integer overflow errors. To simplify, divide the numerator and denominator by their greatest common divisor.
__gcd(a,b)
can be used to compute the greatest common divisor of two numbers in C++. Example usage:
long long a = 32;
long long b = 48;
long long g = __gcd(a, b); // g will be 16
Last updated