WC '02 P9 - A Nerd's Preparation

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 2002

The Head-Monkey is a brilliant tactician, and what's more, she is brilliant at having her troops prepared for battle. This time the battle is for all the proverbial marbles. The Head-Monkey addresses her legion and says: "My fellow monkeys, this battle is for all the marbles!", to which Tiny responds, "Umm, no offence, do we get marbles if we win, Sir?!" After this issue is dealt with, the Head-Monkey decides it's time for the monkeys to prepare themselves for battle. The Head-Monkey is quite a pacifist, and firmly believes in brains before brawn. Confident of the fact that no matter how difficult the final battle is, her monkeys will end up victorious if their minds are sharp, she poses the following problem: Given two fractions \frac a b and \frac c d find the fraction \frac m n between \frac a b and \frac c d (i.e. \frac a b < \frac m n < \frac c d) that has the smallest denominator (i.e. n is minimum). If there is more than one such fraction, output the smallest one.

Constraints

0 < a \le b \le 1\,000

0 < c \le d \le 1\,000

\frac a b < \frac c d

a and b will have no common factors.

c and d will have no common factors.

BONUS: For the truly nerdy monkeys, the Head-Monkey has agreed to give a bonus (i.e., this problem will count as 1.5 problems solved) if the problem is solved for larger constraints: namely, a, b, c and d up to 2 \times 10^9.

Input Specification

The first line contains a single integer, T (1 \le T \le 50), indicating the number of test cases.
Each test case consists of a single line containing four integers separated by a space, namely a, b, c and d. (These correspond to \frac a b and \frac c d)

Output Specification

For each test case, output the fraction that satisfies the above criteria, in the format m/n. Remember, m and n must not have any factors in common.

Sample Input

2
1 3 2 3
1 5 2 5

Sample Output

1/2
1/3

Comments

There are no comments at the moment.