ProgrammingHard

Trial division factorises a number up to 10^12 with for (i = 2; i * i <= n; i++) while (n % i == 0) n /= i;. About how many outer iterations run in the worst case?

  1. A. About 10^12
  2. B. About 10^3
  3. C. About 10^6
  4. D. About 40

Correct answer: C. About 10^6

The loop stops at sqrt(n) = 10^6 when n is prime. Testing up to sqrt(n) is what makes factoring feasible.

More C Programming questions

Exams that ask this topic