#P7679. Distributing Apples among Friends

    ID: 20869 Type: Default 1000ms 256MiB

Distributing Apples among Friends

Distributing Apples among Friends

Mirko has \(R\) red apples and \(G\) green apples. He wants to distribute all of them among some friends so that each friend gets the same number of red apples and the same number of green apples. Note that Mirko does not keep any apples for himself.

For example, if \(R = 4\) and \(G = 8\), there are three possible distributions:

  • Give all apples to 1 friend: the friend gets 4 red apples and 8 green apples.
  • Give apples to 2 friends: each friend gets \(4/2 = 2\) red apples and \(8/2 = 4\) green apples.
  • Give apples to 4 friends: each friend gets \(4/4 = 1\) red apple and \(8/4 = 2\) green apples.

Given two integers \(R\) and \(G\), output all possible distributions. It can be proved that there is always at least one valid distribution.

inputFormat

The input consists of a single line containing two positive integers \(R\) and \(G\), representing the number of red and green apples, respectively.

\(1 \leq R, G \leq 10^9\)

outputFormat

For each valid distribution, output three integers separated by a space: the number of friends, the number of red apples each friend receives, and the number of green apples each friend receives. Output the distributions in increasing order of the number of friends, each on a new line.

sample

4 8
1 4 8

2 2 4 4 1 2

</p>