Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It depends on the numbers you are factoring. Factorization algorithms for large numbers do not find factors in increasing order, thus you need to compute all factors in order to know which is smallest.

If your number is small, or has very small factors, this might be faster :

sage: n = 123456789
sage: bound = 100
sage: next(p for p in primes(bound) if n % p == 0)
3

play around with bound to find the value that works for you. Be aware that if no prime up to bound divides n, the last instruction will raise an exception, in that case you can try a higher bound, or use prime_divisors.