Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C

Problem: Starting with the number 100, subtract the square of the smallest prime factor of the current number each step (the number is always at least 2) until the number becomes 1 or less. How many steps are needed?

  1. A. 4
  2. B. 50
  3. C. 25
  4. D. 10

Correct answer: C. 25

100 and every later value are even, so each step subtracts 2² = 4: 100 → 96 → … → 0 in 25 steps. Using the largest prime factor gives 4 steps, subtracting 2 instead of 4 gives 50, and √100 = 10 is a guess.

More Coding Interview Problems questions

Exams that ask this topic