> For the complete documentation index, see [llms.txt](https://cpgym.uclaacm.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cpgym.uclaacm.com/week-3-math-number-theory/week-3-math-number-theory-1/problem-5-joint-attack.md).

# 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:

```cpp
long long a = 32;
long long b = 48;
long long g = __gcd(a, b); // g will be 16
```
