This is a verified interview question from Titan. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Mathematical Formula using XOR: Titan Online Assessment MNNIT Allahabad" covers key patterns like Arrays.
"You are given two integers N and K. Calculate the value of the following mathematical expression: N ⊕ (N + 1) ⊕ (N + 2) ⊕ ... ⊕ K where ⊕ represents the bitwise XOR operation. Since N and K can be very large, an efficient solution is required. Input Format The first line contains two integers: N K Output Format Print the XOR of all integers from N to K, inclusive. Constraints 1 ≤ N ≤ K ≤ 10^18 Example Input: 3 7 Output: 3 Explanation: 3 ⊕ 4 ⊕ 5 ⊕ 6 ⊕ 7 = 3"
Join thousands of developers practicing for Titan.