AlgoScope

Prime Factorization

Divide out each candidate while it divides. Whatever is left above 1 is prime.

Mathematics, algorithm, beginner
5 has no smaller factor, so it is prime and is the last factor.202122333455
5 has no smaller factor, so it is prime and is the last factor.202122333455

Number Theory Basics: Prime factors of 360

Step, step 7 of 8

Nothing up to the square root divides 5, so 5 is prime itself. It is the last factor.

How number theory basics works

Cost

Best
O(log n)
Average
O(sqrt(n))
Worst
O(sqrt(n))
Space
O(log n)

Taught by the same lesson

Number Theory Basics covers these too, in the same run.