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?

  1. A. 25
  2. B. 30
  3. C. 74
  4. 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

Exams that ask this topic