GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday 20 April 2022

Chef Find XOR Beautiful Solution | CodeChef Problem Solution 2022

You are given an array A of size N and an integer X.

Find the count of all the pairs (i,j) such that ((AiAj) & X)=0. Here  and & denote bitwise XOR and bitwise AND operations respectively.

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer N - the size of the array.
  • The second line contains N space-separated integers A1,A2,,AN - the elements of the array.
  • The third line of each test case contains a single integer X.

Output Format

For each test case, print a single line containing one integer ― the total number of pairs satisfying the condition.

Constraints

  • 1T10
  • 1N105
  • 0Ai,X109

Sample Input 1 

2
4
1 2 3 1
1
3
0 0 0
21

Sample Output 1 

10
9

Explanation

Test case 1: There are 10 pairs of (i,j) (1i,jN) satisfying the condition. These pairs are: (1,1),(1,3),(1,4),(2,2),(3,1),(3,3),(3,4),(4,1),(4,3), and (4,4).

Test case 2: There are 9 pairs of (i,j) (1i,jN) satisfying the condition. These pairs are: (1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2), and (3,3).

No comments:

Post a Comment