Data Structures & AlgorithmsHardGATE CS
How many primes p < 500 have p - 2 or p + 2 also prime (that is, belong to at least one twin-prime pair, counted as individual primes)?
- A. 47
- B. 24
- C. 49
- D. 45
Correct answer: A. 47
There are 24 twin-prime pairs below 500. The primes involved are counted once each; only one pair-sharing prime exists (5 lies in both (3,5) and (5,7)), so the count is 47. Doubling the pair count over-counts the shared prime.
More Coding Interview Problems questions
- 0/1 knapsack with capacity 27: weights [13, 8, 9, 14, 12, 4, 11] and values [25, 19, 16, 27, 22, 8, 23] (item i has weight w[i] and value…
- How many structurally distinct binary trees with 8 nodes have at most 4 levels (a single root alone is 1 level)?
- How many binary strings of length 12 contain neither 101 nor 010 as a substring?
- What are the last three digits of 7^2025?
- In a jump game, a[i] is the maximum jump length from index i (any length from 1 to a[i] is allowed). For a = [3, 1, 4, 1, 5, 9, 2, 6, 5…
- The sequence a1, ..., a14 is generated by a1 = 1 and a(i+1) = (5a(i) + 3) mod 17. How many pairs (i, j) with i < j satisfy a(i) > a(j)?