Integer factorization given enough primes

Click For Summary

Discussion Overview

The discussion revolves around the methods of integer factorization, particularly focusing on the efficiency of brute force versus a prime-based approach. Participants explore the computational complexity involved in factoring numbers less than one million and consider theoretical improvements in factorization techniques.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant notes that brute forcing the factorization of numbers less than one million requires approximately 665 million tests, while a prime-based method results in about 1.398 billion tests.
  • Another participant suggests that since PrimePi(x) grows faster than Sqrt(x), the prime-based method may become less efficient than brute force as the numbers increase.
  • A participant emphasizes that factorization only needs to be brute force up to the square root of the number.
  • One participant introduces the concept of a factor base, mentioning methods like Dixon's algorithm that utilize a set of primes for factorization.
  • There is a suggestion that a variation of the sieve of Eratosthenes could be the fastest method for factoring all numbers below a million.
  • Another participant questions whether existing implementations of these algorithms are available or if one should write their own.

Areas of Agreement / Disagreement

Participants express differing views on the efficiency of the prime-based method compared to brute force, with some suggesting improvements while others highlight limitations. The discussion remains unresolved regarding the best approach to factorization.

Contextual Notes

Some participants mention the need to consider only primes up to the square root of the number being tested, indicating a potential limitation in the initial approach discussed. There are also references to memory constraints when factoring larger numbers.

soandos
Messages
166
Reaction score
0
I realize that this might seems to be a strange question, but after doing some coding i realized the following.

to brute force the factorization of all numbers less than one million takes around 665 million tests (i.e. does this number divide the original).

to do it "smarter" (least i thought) uses a list of the primes, and every time one goes in, it divides the original number by that prime, and tries again. failing that, it goes to the next primes. it stops when the original number is one. the number of tests for this is about 1.398 billion.

first, am i doing something terribly wrong in my implementation of the "smarter" way?
second, is there a better theoretical way to factor numbers given all the primes less than them?
 
Physics news on Phys.org
It also seems that since PrimePi(x) grows faster than Sqrt(x) doing it the "smart" way will continually get worse thant the brute force way.
 
soandos said:
I realize that this might seems to be a strange question, but after doing some coding i realized the following.

to brute force the factorization of all numbers less than one million takes around 665 million tests (i.e. does this number divide the original).

to do it "smarter" (least i thought) uses a list of the primes, and every time one goes in, it divides the original number by that prime, and tries again. failing that, it goes to the next primes. it stops when the original number is one. the number of tests for this is about 1.398 billion.

first, am i doing something terribly wrong in my implementation of the "smarter" way?
second, is there a better theoretical way to factor numbers given all the primes less than them?

http://en.wikipedia.org/wiki/AKS_primality_test
 
I don't want to know if its prime or not, I want the factorization. If i want to know if its prime, I just have to check my list of primes.
 
Factorization only needs to be brute force up to the square root of the number.
 
soandos said:
second, is there a better theoretical way to factor numbers given all the primes less than them?

The set of all primes less than a fixed constant is called a factor base. There are a number of factorization methods that use this such as http://en.wikipedia.org/wiki/Dixon%27s_algorithm" , and its optimizations.
 
Last edited by a moderator:
Thank you, any ideas where there are implementations of it, or should I just write my own?
 
soandos said:
Thank you, any ideas where there are implementations of it, or should I just write my own?

I'm guessing you'll have to write your own. The wiki page gives a good example, though, for factoring 84923. Consider yourself lucky! :P
 
soandos said:
I realize that this might seems to be a strange question, but after doing some coding i realized the following.

to brute force the factorization of all numbers less than one million takes around 665 million tests (i.e. does this number divide the original).

to do it "smarter" (least i thought) uses a list of the primes, and every time one goes in, it divides the original number by that prime, and tries again. failing that, it goes to the next primes. it stops when the original number is one. the number of tests for this is about 1.398 billion.

first, am i doing something terribly wrong in my implementation of the "smarter" way?

Yes, You only need to divide by primes smaller or equal than the square root of the
number you're testing. There are only 168 primes <=1000, so this means less than 168
million tests to factor all the numbers less than 1 million.

If you want to factor ALL the numbers below a million, a variation of th sieve of Eratosthenes will be the fastest. You can mark all numbers divisible by p with p, (so you end up with a list with all the numbers <10^6 with a single prime factor that divides them (if they are not prime). To factor you look up the number in the list, divide by the factor, look up the new number in the list etc.
Of course you will run out of memory around 10^9 .
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
5K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 14 ·
Replies
14
Views
6K
  • · Replies 12 ·
Replies
12
Views
2K