GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The Sieve of Eratosthenes on 2..100 crosses out the multiples of each prime p ≤ 10, starting from p² (p², p² + p, …). How many numbers are crossed out more than once?
- A. 25
- B. 30
- C. 74
- D. 22
Correct answer: A. 25
Total crossings: 2 → 49, 3 → 31, 5 → 16, 7 → 8, i.e. 104 operations on 74 distinct numbers. A number is crossed more than once if it is ≥ p² for at least two of its prime factors in {2, 3, 5, 7}; counting gives 25 such numbers (e.g. 12, 18, 24, 30, …; 20 is crossed only once, since 20 < 5²). 104 − 74 = 30 is the number of extra crossings, not of numbers (30 is crossed 3 times, etc.).
More Algorithms questions
- The Tower of Hanoi with 6 disks is played on three pegs in a row (left, middle, right), and a disk may move only between adjacent pegs…
- Of the 92 solutions of the 8-queens problem (rotations and reflections counted separately), how many have no queen on either of the two…
- Four men m0–m3 and four women w0–w3 have preference lists (best first) m0: w1 w0 w2 w3; m1: w0 w2 w1 w3; m2: w1 w3 w2 w0; m3: w0 w1 w3 w2…
- For n = 5 distinct keys, let M be the worst-case comparisons of top-down merge sort (split ⌈n/2⌉ + ⌊n/2⌋, merge stops when one side is…
- What is the minimum number of comparisons that guarantees finding the median (the third smallest) of 5 distinct elements in the worst case?
- A hash table with chaining has m = 50 slots and stores n = 200 keys; each key is equally likely to be in any slot (simple uniform…