Loading content...
You are provided with two integers: n (the length of a sequence) and start (the initial value of the sequence).
Construct an arithmetic sequence called sequence where each element at index i (using 0-based indexing) is defined by the formula:
sequence[i] = start + 2 × i
This generates a sequence of n evenly spaced integers, starting from start and incrementing by 2 for each subsequent element.
Your task is to compute and return the bitwise XOR of all elements in this sequence. The XOR operation (denoted by ^) compares each bit of its operands: if the bits are different, the result bit is 1; if they are the same, the result bit is 0.
For instance, if n = 4 and start = 0, the sequence would be [0, 2, 4, 6], and the result would be 0 ^ 2 ^ 4 ^ 6.
n = 5
start = 08The arithmetic sequence is [0, 2, 4, 6, 8]. Computing the XOR: 0 ^ 2 ^ 4 ^ 6 ^ 8 = 8. The symbol "^" denotes the bitwise XOR operation.
n = 4
start = 38The arithmetic sequence is [3, 5, 7, 9]. Computing the XOR: 3 ^ 5 ^ 7 ^ 9 = 8.
n = 3
start = 17The arithmetic sequence is [1, 3, 5]. Computing the XOR: 1 ^ 3 ^ 5 = 7.
Constraints