Explanation

You may find trouble to do it how I did, cause this problem has not enough explanation. I am writing an explanation which I found.I think it might help you too .To solve this game, Bob can use a simple formula that depends on the remainder of the given number when divided by 4. The formula is:
XOR(n)= 1.answer will be n (if n mod 4=0)
2.answer will be 1 (if n mod 4=1)
3.answer will be n+1 (if n mod 4=2)
4.answer will be 0 (if n mod 4=3)
This formula works because when we do XOR of numbers, we get 0 as the XOR value just before a multiple of 4. This keeps repeating before every multiple of 4. You can find more details and examples on this page.
Using this formula, Bob can easily find the answer for any test case. For example, for the sample input, he can do:
XOR(1)=1because 1 mod 4 = 1
XOR(4)=4because 4 mod 4 = 0
Therefore, the output is 1 and 4. I hope this helps Bob win the game. 😊

0 comments

No comments so far...

Information

ID
1009
Difficulty
5
Category
Number_Theory , Simulation Click to Show
Tags
(None)
# Submissions
50
Accepted
18
Accepted Ratio
36%
Uploaded By