Sharing apples and bananas
Time limit2sMemory limit512 MB
Given a apples and b bananas, print every common divisor n of a and b with the per-friend apple and banana counts.
- Level
Easy2 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
Areum has a pile of apples and a pile of bananas, but she does not like fruit, so she gives all of it to her friends and keeps nothing for herself. She always shares fairly and never cuts a piece of fruit. If there are friends, all get the same number of apples and the same number of bananas, and no fruit is left over.
For example, with 8 apples and 4 bananas there are only three fair ways to share.
- 1 friend gets all 8 apples and all 4 bananas.
- 2 friends each get 4 apples and 2 bananas.
- 4 friends each get 2 apples and 1 banana.
Write a program that prints every way Areum can share the fruit.
Input
The first line contains the number of apples and the number of bananas , separated by a space. ()
Output
Print every possible way to share the fruit. For each way, print on one line the number of friends, the number of apples one friend gets, and the number of bananas one friend gets, separated by spaces. Print each way exactly once, ordered by increasing number of friends.