• + 1 comment

    Python3 code

    # The XOR is simple enough. The trick is that they haven't given us the
    # numbers to XOR, but their position in the list. To find the actual
    # numbers, determine the number of numbers up to N bits long in the list.
    # Count 0, since we can add any new bit to zero.
    # Then there are 2 numbers with up to 1 bit, 3 with up to 2 bits, etc.
    # To add the numbers with N bits, add the number of numbers with N-2 bits
    # or less to the previous total (the numbers for N-1 bits).
    # The result is the fibonacci sequence, since I just keep adding the last
    # two numbers. And so the number I want is the Zeckendorf representation
    # of the given index, reinterpreted as binary (repeatedly subtracting the
    # largest Fibonacci number available from the index)
    #
    # I've got one case here that is failing, probably just barely failing the time limit.
    # Let's try precalculating the powers as the small speedup needed.
    
    def zeck(n):
        res = 0
        for i in range(f - 1, -1, -1):
            if n >= fib[i]:
                n -= fib[i]
                res += p2[i]
        return res
    
    n = int(input())
    nums = list(map(int, input().strip().split()))
    fib = [1, 2, 3]
    while fib[-1] < 10 ** 18:
        fib.append(fib[-1] + fib[-2])
    f = len(fib)
    p2 = []
    for j in range(f):
        p2.append(2 ** j)
    modulus = 10 ** 9 + 7
    sol = 0
    for j in range(n):
        sol = sol ^ zeck(nums[j])
    print(sol % modulus)