DWRONG - Do It Wrong, Get It Right
In elementary school, students learn to subtract fractions by first getting a common denominator and then subtracting the numerators. However, sometimes a student will work the problem incorrectly and still arrive at the correct answer. For example, for the problem
5/4 - 9/12
one can subtract the numbers in the numerator and then subtract the numbers in the denominator, simplify and get the answer. i.e.
5/4 - 9/12 = -4/-8 = 4/8 = 1/2
For a given fraction b/n, your task is to find all of the values a and m, where a≥0 and m>0, for which
a/m - b/n = (a-b)/(m-n)
There will be several test cases in the input. Each test case will consist of a single line with two integers, b and n (1≤b,n≤106) separated by a single space. The input will end with a line with two 0s.
For each case, output all of the requested fractions on a single line, sorted from smallest to largest. For equivalent fractions, print the one with the smaller numerator first. Output each fraction in the form “a/m” with no spaces immediately before or after the “/”. Output a single space between fractions. Output no extra spaces, and do not separate answers with blank lines.
0/24 5/20 8/16 8/8 5/4
0/28 9/21 9/7
0/24 3/18 3/6