[Solution] OR Tuples solution codechef

OR Tuples solution codechef – Chef has 3 numbers PQ and R. Chef wants to find the number of triples (A, B, C) such that:

  • (A \mid B) = P, (B \mid C) = Q and (C \mid A) = R (Here, \mid denotes the bitwise OR operation)
  • 0 \le A, B, C \lt 2^{20}

[Solution] OR Tuples solution codechef

Can you help Chef?

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of a single line of input containing 3 space-separated integers denoting P, Q and R respectively.

Output Format

For each test case, output a single integer denoting the number of triplets (A, B, C) that satisfy the given conditions.

OR Tuples solution codechef

  • 1 \leq T \leq 10^5
  • 0 \leq P, Q, R \lt 2^{20}

Sample 1:

Input

Output

3
10 12 14
0 5 5
0 0 7
4
1
0

OR Tuples solution codechef Explanation:

Test case 1: The following 4 triplets (A, B, C) satisfy A \mid B = 10, B\mid C = 12, and C\mid A = 14(2, 8, 12), (10, 0, 12), (10, 8, 4), and (10, 8, 12).

Test case 2: The following triplet (A, B, C) satisfies A \mid B = 0, B\mid C = 5, and C\mid A = 5(0, 0, 5).

Test case 3: There are no triplets satisfying all the conditions.

For Solution

“Click Here”

Leave a Comment