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 ab and cd find the fraction mn between ab and cd (i.e. ab<mn<cd) that has the smallest denominator (i.e. n is minimum). If there is more than one such fraction, output the smallest one.

Constraints

0<ab1000

0<cd1000

ab<cd

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×109.

Input Specification

The first line contains a single integer, T (1T50), 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 ab and cd)

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

Copy
2
1 3 2 3
1 5 2 5

Sample Output

Copy
1/2
1/3

Comments

There are no comments at the moment.