Fractional XOR Maximization
Time limit2sMemory limit512 MB
Given rational intervals [a, b] and [c, d], find the supremum of the XOR of binary expansions of one number from each interval.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Greedy, Math
- Solved
- No attempts yet
Problem
Define the bitwise XOR operation for any two real numbers and as follows. The on the right side is the integer bitwise XOR. For example, , , and .
The supremum of a set , written , is the least real number that is greater than or equal to every element of .
You are given four non-negative rational numbers , , , and . Find . In other words, find the least value that is greater than or equal to every XOR value formed by an element of and an element of .
Input
The first line contains (), the number of test cases. Each test case has two lines. The first line contains four integers , , , (, ), which describe and . The second line describes and in the same format. Every fraction is irreducible, and and hold.
Output
Print lines. The -th line contains the numerator and denominator of for the -th test case, separated by a single space, as an irreducible fraction.
Hint
In the first test case, the answer is . Choosing from the first interval and from the second makes the XOR value arbitrarily close to for a large enough integer , but no value equal to or greater than is reachable.