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?
- A. 10
- B. 8
- C. 7
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Coins of values 1, 5, 6 and 9 are available in unlimited supply. What is the minimum number of coins needed to make exactly 11?
- In how many ways can 100 paise be paid using coins of 1, 5, 10 and 25 paise, where the order of coins does not matter?
- In how many ways can 9 identical sweets be given to 4 distinct children so that every child gets at least one sweet?
- How many words of length 6 over a three-letter alphabet {x, y, z} have no two adjacent letters equal?
- How many permutations p of 1, 2, ..., 6 satisfy p[i] ≤ i + 1 for every position i (1-based)?
- How many distinct arrangements of the letters of "aabbcc" have no two adjacent letters equal?