nishanth17 / factor

Fast prime factorization in Python
25 stars 7 forks source link

factor

Fast prime factorization in Python. Factors most 50-60 digit numbers within a minute or so (with PyPy).
The algorithm used depends on the size of the input

Usage

All you have to do is run the file factor.py, enter a number, and hit Enter. Here's an example in terminal:

python factor.py
Enter a number: 15

Factoring 15...
Number of digits: 2
Finding small prime factors...
Prime factors found: 3, 5

15 = 3^1 * 5^1

Time: 5.00679016113e-05 s

and another...

Enter number: 37897387397398739739826929827929827927927762729872987928

Factoring 37897387397398739739826929827929827927927762729872987928...
Number of digits: 56
Finding small prime factors...
Prime factors found: 2, 3
Factoring 1579057808224947489159455409497076163663656780411374497 with ECM...
Number of digits: 55
Bounds: 250000 128992510
Sieving primes...
Stage 2 found factor!
Found factor 67246307
Factoring 67246307...
Number of digits: 8
67246307 is prime!
Factoring 23481702991138940747474138758238071923617408171...
Number of digits: 47
Factoring 23481702991138940747474138758238071923617408171 with ECM...
Number of digits: 47
Bounds: 50000 12746592
Sieving primes...
Tried 40 random curves...
Tried 80 random curves...
Tried 120 random curves...
Tried 160 random curves...
Stage 2 found factor!
Found factor 4788272261623351
Factoring 4788272261623351...
Number of digits: 16
4788272261623351 is prime!
Factoring 4904003303934522319753958187821...
Number of digits: 31
4904003303934522319753958187821 is prime!

37897387397398739739826929827929827927927762729872987928 = 2^3 * 3^1 * 67246307^1 * 4788272261623351^1 * 4904003303934522319753958187821^1

Time: 24.7774269581 s

References