#P7679. [COCI 2008/2009 #5] JABUKA
[COCI 2008/2009 #5] JABUKA
Description
Mirko has red apples and 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 red apples and green apples. Then all possible ways to distribute the apples are:
- Give them to one friend, that is, give all red apples and green apples to this friend.
- Give them to two friends, where each friend receives red apples and green apples.
- Give them to four friends, where each friend receives red apple and green apples.
Now given , 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 , 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.
4 8
1 4 8
2 2 4
4 1 2
15 12
1 15 12
3 5 4
42 105
1 42 105
3 14 35
7 6 15
21 2 5
Hint
Constraints
For all testdata, .
Source
This problem comes from COCI 2008-2009 CONTEST 5 T2 JABUKA. Using the original testdata settings, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5
京公网安备 11011102002149号