Problems > XOR of 1..N

XOR of 1..N

Difficulty: 1300 2000 ms 128 MB

math bitwise

Compute 1 ⊕ 2 ⊕ 3 ⊕ … ⊕ N (bitwise XOR).

Input: one integer N.

Output: the XOR of all integers from 1 to N.

Constraints:

  • 1 ≤ N ≤ 1018

Sample Tests

Input 1
7
Output 1
0
Input 2
3
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.