Well, the well-known solution is to test the value of n modulo 2. If it’s zero, then the number is even, otherwise it’s odd. But how fast is it?
16 seconds! That’s a lot… Let’s try an alternative approach. Let’s do bitwise operations. You can use the bitwise AND operator and check the least significant bit of the integer. If the least significant bit is 0, the number is even; if it’s 1, the number is odd.
I tried both versions (modulo 2 and bitwise AND) and got the same result. I think the optimizer recognizes modulo 2 and converts it to bitwise AND.