You are given an array of n integer numbers a1, a2, . . . , an. Calculate the number of pair of indices (i, j) such that 1 ≤ i < j ≤ n and ai xor aj = 0.
Input format
- First line: n denoting the number of array elements
- Second line: n space-separated integers a1, a2, . . . , an.
Output format
Output the required number of pairs.
Constraints
1 ≤ n ≤ 106 1 ≤ ai ≤ 109
SAMPLE INPUT
5
1 3 1 4 3
SAMPLE OUTPUT
2
Explanation
The 2 pair of indices are (1, 3) and (2,5).
ANSWER:
#include <stdio.h>
int main()
{
int n, arr[1000000], i, j, count;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
count = 0;
for (i = 0; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
if (arr[i] == arr[j])
{
count++;
}
}
}
printf("%d", count);
return 0;
}
OUTPUT:
5
1 3 1 4 3
2
No comments:
Post a Comment