Data Structures & AlgorithmsModerateICPC regional · number theory

Problem: What is the time complexity of finding all prime factors of n up to 10^12 by trial division?

  1. A. O(log n)
  2. B. O(n)
  3. C. O(sqrt n)
  4. D. O(n log n)

Correct answer: C. O(sqrt n)

Trial division up to sqrt(n) takes about 10^6 steps for n = 10^12.

More Coding Interview Problems questions

Exams that ask this topic