Even or Odd

Easy · rating 800 · math

Read an integer n. Print Even if it is even, otherwise Odd.

Constraints: -1018 ≤ n ≤ 1018

Editorial

Even or Odd tests a number's parity with the modulo operator: n % 2 == 0 means even (and it works for negatives). For very large values, checking the last bit with n & 1 is an equivalent, fast alternative.

print('Even' if n % 2 == 0 else 'Odd')

Complexity

Time: O(1). Space: O(1).

Open Even or Odd in Code Arena →