0

Oniwa and Amix Numbers

Difficulty: MEDIUM
Contributed By
Yash Bansal
Avg. time to solve
30 min
Success Rate
70%

Problem Statement
Suggest Edit

Nandy, Oniwa and Amix were having three integers ‘A’ ,’B’ ,’C’ .They want to a minimum number of Flip operation required in either ‘A’ or ‘B’ to make ‘A’ or ‘B’ == ‘C’ where ‘or’ is bitwise OR operation. The flip operation consists of changing a bit from 1 to 0 or from 0 to 1.

Nandy, Oniwa and Amix have to attend the meet of elite coders. So please find the minimum number of flips required to in A or B to make A or B equal to C.

Input Format:
The first line of input contains an integer ‘T’ denoting the number of test cases. 

The first and only line of the test case consists of three integers ‘A’, ‘B’, and ‘C’.
Output Format:
For each test case, print a single line containing a single integer denoting the minimum number of flips required.

The output of each test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 11
1 <= A <= 10 ^ 9
1 <= B <= 10 ^ 9
1 <= C <= 10 ^ 9

Where 'T' is the number of test cases and 'A', 'B', 'C' are given integers.

Time Limit: 1 sec.
Sample Input 1:
2
2 4 5
4 2 6
Sample Output 1:
2
0
Sample Explanation:
For the first test case:-
One of the possible flip operations are :-
The binary representation of 2 is 10.
Convert 10 to 01. 2 flip operations are used .
The binary representation of 4 is 100.
The or of (100 or 01) is 101.
Thus 2 flip operations are used.

For the second test case:-
The binary representation of 2 is 10.
The binary representation of 4 is 100.
The or of (10) or (100) is 110.
Thus 0 flip operations are required.
Sample Input 2:
2
14 2 0
15 6 12
Sample Output 2:
4
3
Reset Code
Full screen
copy-code
Console