def is_even(n: int):
import mathreturn sum(math.floor(abs(math.cos(math.pi/2 * n/i))) for i in range(1, 2 ** 63)) > 0
spoiler
i can’t imagine how long it’ll take to run, my computer took over 3 minutes to compute one value when the upper bound was replaced with 230. but hey, at least it’s O(1).
here’s a constant time solution:
def is_even(n: int): import math return sum(math.floor(abs(math.cos(math.pi/2 * n/i))) for i in range(1, 2 ** 63)) > 0
spoiler
i can’t imagine how long it’ll take to run, my computer took over 3 minutes to compute one value when the upper bound was replaced with 230. but hey, at least it’s O(1).
Nice, how about bitwise & operator?