Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

How many unordered pairs of positions in [3, 4, 7, 10, 2, 9] have an element sum that is a prime number?

  1. A. 10
  2. B. 8
  3. C. 7
  4. D. 15

Correct answer: B. 8

Test each pair's sum for primality with trial division up to its square root; the array is small enough for an O(n²) pass. Counting pairs with odd sums (a parity shortcut that only helps for prime 2) gives a different number.

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

Exams that ask this topic