I'm looking for an implementation or cleanup algorithm to get a simple factorization of N in any python, pseudo-code, or other well readable code. There are several requirements / facts:
- N is between 1 and ~ 20 digits
- No pre-computed lookup table, memoization is ok.
- No need to be mathematically proven (for example, if necessary, can rely on the Goldbach hypothesis)
- It is not necessary to be precise, it is allowed to be probabilistic / deterministic, if necessary
I need an algorithm for quick simple factorization, not only for myself, but also for use in many other algorithms, such as calculating Euler phi (n).
I tried other algorithms from Wikipedia and such, but I could not understand them (ECM), or I could not create a working implementation from the algorithm (Pollard-Brent).
I'm really interested in the Pollard-Brent algorithm, so any information / implementations on it would be really nice.
Thank!
EDIT
After a bit of communication, I created a fairly quick prime / factorization module. It combines an optimized trial division algorithm, the Pollard-Brent algorithm, the miller-rabin primitive test and the fastest live broadcast I found on the Internet. gcd is a regular implementation of the Euclidean GCD (binary Euclid GCD is much slower than normal).
Bounty
Oh joy, you can get generosity! But how can I win it?
- Look for an optimization or error in my module.
- Provide alternative / best algorithms / implementations.
The answer that is most comprehensive / constructive receives a reward.
And finally, the module itself:
import random def primesbelow(N):
python algorithm prime-factoring
orlp Jan 10 2018-11-11T00: 00Z
source share