Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many integers n with 1 <= n <= 200 have both n and n + 2 prime?

  1. A. 16
  2. B. 1
  3. C. 15
  4. D. 46

Correct answer: C. 15

Test primality by trial division for n and n + 2; the twin prime pairs up to about 200 are counted by their lower element. Checking n and n + 1 (second option) finds only the pair (2, 3).

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

Exams that ask this topic