Given an array A[ ] of N integers, calculate the sum of "A[i] & A[j]" of all the pairs formed by the given array, where & is the bitwise AND operator.
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
The first line of each test case contains a positve integer N, denoting the length of the array A[ ].
The second line of each test case contains a N space seprated positve integers, denoting the elements of the array A[ ].
Print out the sum of products of all pairs formed by the array.
1 <= T <= 100
2 <= N <=30
0 <= A[ ] <= 100
5 10 15
10 20 30 40
20 16 32 50 64
For the above test case
Required Value = (5 & 10) + (5 & 15) + (10 & 15)
= 0 + 5 + 10
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.