## COCI '08 Contest 5 #2 Jabuka

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Mirko has red and green apples to share with some of his friends, so that all of them receive the same number of red apples and also the same number of green apples. Mirko does not like apples himself so he doesn't want to be left with any apples afterward.

For example, if Mirko has red and green apples, he can divide them in three ways:

1. One friend gets all red and all green apples;
2. Two friends each receive red apples and green apples;
3. Four friends each receive red and green apples.

Write a program that outputs all ways for Mirko to divide his apples. Assume Mirko has an infinite supply of friends to give apples to.

#### Input Specification

The first line contains two positive integers and separated by a space , the numbers of red and green apples.

#### Output Specification

For each possible distribution, output three integers , and on one line. The number is the number of friends that will receive apples. The numbers and tell how many red and green apples each of them will receive.

Each distribution needs to be output exactly once. You may output the distributions in any order.

#### Sample Input 1

4 8

#### Sample Output 1

1 4 8
2 2 4
4 1 2

#### Sample Input 2

15 12

#### Sample Output 2

3 5 4
1 15 12

#### Sample Input 3

42 105

#### Sample Output 3

1 42 105
3 14 35
7 6 15
21 2 5