0

What is a good algorithm for decomposing a number into a product of primes? What would be its time complexity?

Vaolter
  • 1,711
kolonel
  • 1,142

3 Answers3

4

The best known algorithm for factorization is the General Number Field Sieve which runs in time roughly $(\log n)^{C(\log n)^{1/3}(\log\log n)^{2/3}}$.

This is much, much faster than trial division. For example, a hundred-digit number can be factored in about a day with this method, compared to $10^{33}$ years for trial division.

Still, a practical approach will combine a bit of trial division with a bit of searching for small factors with ECM before moving to NFS.

Charles
  • 32,122
3

There is a whole branch of cryptography that relies on the notion that there is not really a "good" algorithm that can decompose any arbitrary number into prime factors. That is, someone who wants to encrypt some data will choose a number that is the product of very large primes, and there is no known algorithm to extract those primes from their product in any reasonable amount of time. See https://stackoverflow.com/questions/439870/why-are-primes-important-in-cryptography

Also see Algorithms for Finding the Prime Factorization of an Integer, which I think is the same question as this one.

David K
  • 98,388
2

This site, for instance, implements the elliptic curve method. It is pretty quick, as you can see, but by no means the fastest. That would be the general number field sieve. More information can be found here. Hope this helps.

Lucian
  • 48,334
  • 2
  • 83
  • 154