Problem 301

completed October 27, 2020

Comments

This problem was really really easy. I’m wondering if I missed something. But, it told me I could look up the algorithm for X(a, b, c), so I did.

Runs in about 3 seconds on pypy3.

Code

def X(a, b, c):
    return a ^ b ^ c

def solve(n):
    total = 0
    for k in range(1, n + 1):
        if not X(k, 2*k, 3*k):
            total += 1
    return total

if __name__ == '__main__':
    n = 1 << 30
    print(solve(n))