Problem #487
✰ - click to bookmark
★ - in your bookmarks
Tags:
unlabeled
For this nice puzzle we again are much indebted to Clive Fraser - many thanks!
You will be given 3 positive integers: A, B and C. You are to reduce the size of any or all of these integers in order to equalise their values, to a common end result D. However, only certain reductions in size can be applied. There are 63 of these. Their values are : 1, 2, 4, 8, 16, 32, ..., 4611686018427387904. It should be clear that the values start at 1 and that successive values are double the previous value. The final allowed value is 2^62. Values from this list can be used at most once. For example, if the current size of B is reduced by 8, then 8 can no longer be used to reduce the current size of A, B or C. You can continue to reduce the size of a number provided that each reduction uses a value from the list which has not already been used. It may not be necessary to reduce all three numbers in order to reach the common end point D.
It is guaranteed that the three integers given in the problem can be reduced to at least one common end result D, following the rules described above. If it is possible to reach more than one common end result, you are asked to find the largest of these.
Consider a simple example where A = 180, B = 178 and C = 300. We can make the reductions shown below to reach the value of D = 172.
A = 180 - 8 = 172
B = 178 - 2 - 4 = 172
C = 300 - 128 = 172
172 is the largest value of any common end point D which can be achieved for these three numbers.
Input/Output description: The first line of the input data will contain a single integer N, representing the number of problems to solve. N lines will follow. Each of these contains three space-separated integers A, B and C. For each problem you must find the largest common end point D, after applying a valid series of reductions. Combine all answers into a single string, separated by spaces.
Example:
input:
5
180 178 300
3045 999 1021
28695 39195 45146
194580 146837 151892
4073471 4539851 3562959
answer:
172 997 28695 142612 3491263