teacher
Sign in

Math Basics for Contests

Parity, divisibility, remainders with negatives, gcd and lcm with Euclid, ceiling division, sums of series and digit tricks.

25 minCF 800–12006 interactive10 problems

Parity

Parity is whether an integer is even or odd. It sounds trivial, yet many 800-1000 problems reduce to it.

OperationResult
even + even, odd + oddeven
even + oddodd
even x anythingeven
odd x oddodd
  • Test with x % 2 == 0 for even. For odd, test x % 2 != 0, never x % 2 == 1, because -3 % 2 is -1 in C++ and Java.
  • A sum of k odd numbers has the parity of k.
Quick check
1 / 2
a and b are both odd. Which value is always even?
2 / 2
In C++, what does (-3) % 2 == 1 evaluate to?
1 of 8