Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

What is the number of integer pairs (x, y) with 1 <= x <= y <= 20 for which gcd(x, y) = 1 and x + y is even?

  1. A. 43
  2. B. {C+7}
  3. C. 45
  4. D. 42

Correct answer: D. 42

Coprime pairs with an even sum must both be odd (two odd numbers have an even sum, and an odd-even pair is never even). Checking the pairs with both coordinates odd reduces the search.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic