×

# count all pairs with given XOR x in given array.

 2 Given an array A[] of size N and a number x. count all the pairs in array such that A[i]^A[j]=x. DON'T PROPOSE THE SOLUTIONS WITH O(N^2) AND ALSO THE SOLUTION GIVEN ON GEEKSFORGEEKS THIS IS THE SOLUTION PROVIDED BY CODEFORCES Note that if then . Keep in numx the number of repetitions of number x. Now for each x, add to answer. Then divide answer by 2 (if X is 0, don’t). Time complexity: O(n). Corner case #1 : Some codes got WA when X is 0. Corner case #2 : Some codes got RE because can be as large as max(x, y)·2. I couldn't understand this solution please explain this one or some other approach. asked 07 Dec '16, 09:35 1★arpit728 683●17●65 accept rate: 10%

# include<stdio.h>

int main() { int A[100],N,x,k,i,j, count=0; printf("enter the size of array {max100}"); scanf("%d",&N); printf("enter the elements of array "); for(i=0;i<N;i++) { scanf("%d",&A[i]); } printf("enter the value of x="); scanf("%d",&x);

for(i=0;i<N;i++)
{
for(j=i;j<N;j++)
{
k=A[i]*A[j];
if(k==x)
{
count=count+1;
}
}
}
printf("\nthe number of possible pairs=%d",count);


}

1
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×678
×303
×234
×141

question asked: 07 Dec '16, 09:35

question was seen: 2,899 times

last updated: 30 Apr '17, 19:03