Count all possible pairs in an array with even XOR greater than 2

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-2
down vote

favorite












Given an array $A_1,A_2, dots, A_N$. We have to tell how many pairs $(i, j)$ exist such that $1 leq i < j leq N$ and $A_i textXOR A_j$ is an even number greater than 2.
I want an $mathcalO(N)$ algorithm or at worst an $mathcalO(Nlog N)$ algorithm. Here, $N$ can be up to $10^5$.










share|cite|improve this question



















  • 1




    In other words, $A_i$ and $A_j$ are either equal, or differ only in ther second-lowest bit?
    – Hagen von Eitzen
    Sep 10 at 8:04











  • "is an even no greater than 2": as far as I know, this means 0 or 2. Please confirm.
    – Yves Daoust
    Sep 10 at 8:10










  • @YvesDaoust even no except 0 or 2
    – tanweer anwar
    Sep 10 at 8:15










  • @tanweeranwar: please write in unambiguous English.
    – Yves Daoust
    Sep 10 at 8:17











  • @tanweeranwar - do you mean an even number that is "no greater than 2" i.e. 0 or 2 - or do you mean an even number (abbreviated "no") that is greater than 2 i.e. 4,6,8, etc.
    – gandalf61
    Sep 10 at 8:40














up vote
-2
down vote

favorite












Given an array $A_1,A_2, dots, A_N$. We have to tell how many pairs $(i, j)$ exist such that $1 leq i < j leq N$ and $A_i textXOR A_j$ is an even number greater than 2.
I want an $mathcalO(N)$ algorithm or at worst an $mathcalO(Nlog N)$ algorithm. Here, $N$ can be up to $10^5$.










share|cite|improve this question



















  • 1




    In other words, $A_i$ and $A_j$ are either equal, or differ only in ther second-lowest bit?
    – Hagen von Eitzen
    Sep 10 at 8:04











  • "is an even no greater than 2": as far as I know, this means 0 or 2. Please confirm.
    – Yves Daoust
    Sep 10 at 8:10










  • @YvesDaoust even no except 0 or 2
    – tanweer anwar
    Sep 10 at 8:15










  • @tanweeranwar: please write in unambiguous English.
    – Yves Daoust
    Sep 10 at 8:17











  • @tanweeranwar - do you mean an even number that is "no greater than 2" i.e. 0 or 2 - or do you mean an even number (abbreviated "no") that is greater than 2 i.e. 4,6,8, etc.
    – gandalf61
    Sep 10 at 8:40












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Given an array $A_1,A_2, dots, A_N$. We have to tell how many pairs $(i, j)$ exist such that $1 leq i < j leq N$ and $A_i textXOR A_j$ is an even number greater than 2.
I want an $mathcalO(N)$ algorithm or at worst an $mathcalO(Nlog N)$ algorithm. Here, $N$ can be up to $10^5$.










share|cite|improve this question















Given an array $A_1,A_2, dots, A_N$. We have to tell how many pairs $(i, j)$ exist such that $1 leq i < j leq N$ and $A_i textXOR A_j$ is an even number greater than 2.
I want an $mathcalO(N)$ algorithm or at worst an $mathcalO(Nlog N)$ algorithm. Here, $N$ can be up to $10^5$.







combinatorics algorithms






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Sep 10 at 10:12

























asked Sep 10 at 7:37









tanweer anwar

13




13







  • 1




    In other words, $A_i$ and $A_j$ are either equal, or differ only in ther second-lowest bit?
    – Hagen von Eitzen
    Sep 10 at 8:04











  • "is an even no greater than 2": as far as I know, this means 0 or 2. Please confirm.
    – Yves Daoust
    Sep 10 at 8:10










  • @YvesDaoust even no except 0 or 2
    – tanweer anwar
    Sep 10 at 8:15










  • @tanweeranwar: please write in unambiguous English.
    – Yves Daoust
    Sep 10 at 8:17











  • @tanweeranwar - do you mean an even number that is "no greater than 2" i.e. 0 or 2 - or do you mean an even number (abbreviated "no") that is greater than 2 i.e. 4,6,8, etc.
    – gandalf61
    Sep 10 at 8:40












  • 1




    In other words, $A_i$ and $A_j$ are either equal, or differ only in ther second-lowest bit?
    – Hagen von Eitzen
    Sep 10 at 8:04











  • "is an even no greater than 2": as far as I know, this means 0 or 2. Please confirm.
    – Yves Daoust
    Sep 10 at 8:10










  • @YvesDaoust even no except 0 or 2
    – tanweer anwar
    Sep 10 at 8:15










  • @tanweeranwar: please write in unambiguous English.
    – Yves Daoust
    Sep 10 at 8:17











  • @tanweeranwar - do you mean an even number that is "no greater than 2" i.e. 0 or 2 - or do you mean an even number (abbreviated "no") that is greater than 2 i.e. 4,6,8, etc.
    – gandalf61
    Sep 10 at 8:40







1




1




In other words, $A_i$ and $A_j$ are either equal, or differ only in ther second-lowest bit?
– Hagen von Eitzen
Sep 10 at 8:04





In other words, $A_i$ and $A_j$ are either equal, or differ only in ther second-lowest bit?
– Hagen von Eitzen
Sep 10 at 8:04













"is an even no greater than 2": as far as I know, this means 0 or 2. Please confirm.
– Yves Daoust
Sep 10 at 8:10




"is an even no greater than 2": as far as I know, this means 0 or 2. Please confirm.
– Yves Daoust
Sep 10 at 8:10












@YvesDaoust even no except 0 or 2
– tanweer anwar
Sep 10 at 8:15




@YvesDaoust even no except 0 or 2
– tanweer anwar
Sep 10 at 8:15












@tanweeranwar: please write in unambiguous English.
– Yves Daoust
Sep 10 at 8:17





@tanweeranwar: please write in unambiguous English.
– Yves Daoust
Sep 10 at 8:17













@tanweeranwar - do you mean an even number that is "no greater than 2" i.e. 0 or 2 - or do you mean an even number (abbreviated "no") that is greater than 2 i.e. 4,6,8, etc.
– gandalf61
Sep 10 at 8:40




@tanweeranwar - do you mean an even number that is "no greater than 2" i.e. 0 or 2 - or do you mean an even number (abbreviated "no") that is greater than 2 i.e. 4,6,8, etc.
– gandalf61
Sep 10 at 8:40















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2911641%2fcount-all-possible-pairs-in-an-array-with-even-xor-greater-than-2%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2911641%2fcount-all-possible-pairs-in-an-array-with-even-xor-greater-than-2%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

tkz-euclide: tkzDrawCircle[R] not working

How to combine Bézier curves to a surface?

1st Magritte Awards