> 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

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
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cpgym.uclaacm.com/week-3-math-number-theory/week-3-math-number-theory-1/problem-5-joint-attack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
