#Q24. 「一本通 1.3 练习 1」埃及分数
「一本通 1.3 练习 1」埃及分数
Description
Source: BIO 1997 Round 1 Question 3
In ancient Egypt, people used sums of unit fractions (of the form , where is a natural number) to represent all rational numbers. For example: , but is not allowed because the addends are identical. For a fraction , there are many ways to represent it, but which one is the best? First, a representation with fewer addends is better than one with more. Second, among representations with the same number of addends, the one with the largest smallest fraction is preferred. For example:
$$\begin{aligned} \frac{19}{45} &= \frac{1}{3} + \frac{1}{12} + \frac{1}{180}\\ \frac{19}{45} &= \frac{1}{3} + \frac{1}{15} + \frac{1}{45}\\ \frac{19}{45} &= \frac{1}{3} + \frac{1}{18} + \frac{1}{30}\\ \frac{19}{45} &= \frac{1}{4} + \frac{1}{6} + \frac{1}{180}\\ \frac{19}{45} &= \frac{1}{5} + \frac{1}{6} + \frac{1}{18}\\ \end{aligned} $$The best representation is the last one because is larger than $\dfrac{1}{180}, \dfrac{1}{45}, \dfrac{1}{30}, \dfrac{1}{18}$.
Note that there may be multiple optimal solutions. For example:
Since the smallest fractions in the first and second methods are the same, both are considered optimal solutions.
Given and , write a program to compute the best representation. It is guaranteed that the optimal solution satisfies: the smallest fraction .
Input Format
One line containing two integers, the values of and .
Output Format
Output several numbers, arranged in ascending order, representing the denominators of the unit fractions.
Sample 1
19 45
5 6 18
Constraints and Hints