Counts Zeros Xor Pairs (GFG)
Given an array A[] of size N. Find the number of pairs (i, j) such that
XOR
= 0, and 1 <= i < j <= N.
Input:
The first line of the input contains a single integer T denoting the number of test cases. The first line of each test case contains N. followed by N separate integers.
Output:
For each test case, output a single integer i.e counts of Zeros Xors Pairs
Constraints
1 ≤ T ≤ 200
2 ≤ N ≤ 10^5
1 ≤ A[i] ≤ 10^5
Example:
Input :
2
5
1 3 4 1 4
3
2 2 2
Output :
2
3
Explanation :
Test Case 1: Index( 0, 3 ) and (2 , 4 ) are only pairs whose xors is zero so count is 2.
SOLUTION:
for i in range(int(input())):
n=int(input())
p=list(map(int,input().split()))
p=sorted(p)
count=0
for i in range(0,n-1):
for j in range(i+1,n):
if p[i]==p[j]:
count+=1
print(count)
Comments
Post a Comment