We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Okay maybe I get another tip. XOR has mathematical interessing properties: Commutativity, Associativity and A⊕A=0. And if you study the given function et take an example.
here the whole sequence:
A0 = 0
A1 = 0⊕1
A2 = 0⊕1⊕2
A3 = 0⊕1⊕2⊕3
A4 = 0⊕1⊕2⊕3⊕4
A5 = 0⊕1⊕2⊕3⊕4⊕5
A6 = 0⊕1⊕2⊕3⊕4⊕5⊕6
A7 = 0⊕1⊕2⊕3⊕4⊕5⊕6⊕7
A8 = 0⊕1⊕2⊕3⊕4⊕5⊕6⊕7⊕8
...
Test case 0: (Li,Ri) = (2,4)
so we get:
A2 = 0⊕1⊕2
A3 = 0⊕1⊕2⊕3
A4 = 0⊕1⊕2⊕3⊕4
et compute A2⊕A3⊕A4:
A2⊕A3⊕A4 = 0⊕1⊕2⊕0⊕1⊕2⊕3⊕0⊕1⊕2⊕3⊕4
and factorize it:
A2⊕A3⊕A4 = 0⊕0⊕0⊕1⊕1⊕1⊕2⊕2⊕2⊕3⊕3⊕4
and then reduce it:
A2⊕A3⊕A4 = 1⊕2⊕4
you finaly get the result:
A2⊕A3⊕A4 = 7.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Xor-sequence
You are viewing a single comment's thread. Return to all comments →
Okay maybe I get another tip. XOR has mathematical interessing properties: Commutativity, Associativity and A⊕A=0. And if you study the given function et take an example.
here the whole sequence:
A0 = 0
A1 = 0⊕1
A2 = 0⊕1⊕2
A3 = 0⊕1⊕2⊕3
A4 = 0⊕1⊕2⊕3⊕4
A5 = 0⊕1⊕2⊕3⊕4⊕5
A6 = 0⊕1⊕2⊕3⊕4⊕5⊕6
A7 = 0⊕1⊕2⊕3⊕4⊕5⊕6⊕7
A8 = 0⊕1⊕2⊕3⊕4⊕5⊕6⊕7⊕8
...
Test case 0: (Li,Ri) = (2,4)
so we get:
A2 = 0⊕1⊕2
A3 = 0⊕1⊕2⊕3
A4 = 0⊕1⊕2⊕3⊕4
et compute A2⊕A3⊕A4:
A2⊕A3⊕A4 = 0⊕1⊕2⊕0⊕1⊕2⊕3⊕0⊕1⊕2⊕3⊕4
and factorize it:
A2⊕A3⊕A4 = 0⊕0⊕0⊕1⊕1⊕1⊕2⊕2⊕2⊕3⊕3⊕4
and then reduce it:
A2⊕A3⊕A4 = 1⊕2⊕4
you finaly get the result:
A2⊕A3⊕A4 = 7.