P7679 [COCI 2008/2009 #5] JABUKA

Description

Mirko has $R$ red apples and $G$ green apples. He wants to give them to several friends so that every friend receives the same number of red apples and the same number of green apples. Since Mirko himself does not like apples, he will not keep any apples for himself. For example, suppose Mirko has $4$ red apples and $8$ green apples. Then all possible ways to distribute the apples are: - Give them to one friend, that is, give all $4$ red apples and $8$ green apples to this friend. - Give them to two friends, where each friend receives $2$ red apples and $4$ green apples. - Give them to four friends, where each friend receives $1$ red apple and $2$ green apples. Now given $R, G$, please help Mirko find all possible ways to distribute the apples. It can be proven that at least one valid distribution always exists.

Input Format

The input contains only one line with two integers $R, G$, representing the number of red apples and the number of green apples.

Output Format

Output several lines. Each line contains three integers: the number of friends, the number of red apples each friend receives, and the number of green apples each friend receives. If there are multiple solutions, output them in **increasing order of the number of friends**. It is guaranteed that the output will not exceed the output limit.

Explanation/Hint

**Constraints** For all testdata, $1\leqslant R,G\leqslant 10^9$. **Source** This problem comes from **_[COCI 2008-2009](https://hsin.hr/coci/archive/2008_2009/) [CONTEST 5](https://hsin.hr/coci/archive/2008_2009/contest5_tasks.pdf) T2 JABUKA_**. Using the original testdata settings, the full score is $50$ points. Translated and organized by [Eason_AC](https://www.luogu.com.cn/user/112917). Translated by ChatGPT 5