If you want to factorize many large numbers, then you might be better off first finding the prime numbers up to sqrt(n)
(e.g. using Sieve of Eratosthenes). Then you have to check only whether those prime numbers are factors instead of testing all i <= sqrt(n)
.