Integer factorization given enough primes

In summary, the conversation discusses different methods for factoring numbers and compares the number of tests required for each method. The "smarter" method involves using a list of primes and dividing the original number by each prime until it is reduced to 1. However, it is suggested that only primes less than or equal to the square root of the number need to be used, significantly reducing the number of tests required. A variation of the sieve of Eratosthenes is also mentioned as a fast method for factoring numbers.
  • #1
soandos
166
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
  • #2
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.
 
  • #3
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
 
  • #4
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.
 
  • #5
Factorization only needs to be brute force up to the square root of the number.
 
  • #6
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:
  • #7
Thank you, any ideas where there are implementations of it, or should I just write my own?
 
  • #8
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
 
  • #9
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 .
 

1. What is integer factorization?

Integer factorization is the process of breaking down a composite number into its prime factors. This is important in mathematics and computer science, as it is used in encryption and cryptography algorithms.

2. Why is it important to have enough primes for integer factorization?

The more prime numbers we have, the easier it is to factorize a composite number. This is because prime numbers are the building blocks of all other numbers, and having a diverse set of primes allows for more efficient and accurate factorization.

3. How many primes are needed for efficient integer factorization?

There is no specific number of primes needed for efficient factorization, as it depends on the size and complexity of the number being factorized. However, having a large pool of primes (hundreds or thousands) is generally ideal for efficient factorization.

4. How does integer factorization relate to cryptography?

Cryptography algorithms use integer factorization as a key component in creating secure codes. By utilizing large prime numbers, the encryption becomes more difficult to break, as it would require significant computing power to factorize the numbers.

5. Can integer factorization be done efficiently for any number?

No, there are certain numbers that are considered "hard" to factorize, meaning it would take a significant amount of time and computing power to find their prime factors. These numbers are often used in cryptography to ensure the security of encrypted data.

Similar threads

  • Programming and Computer Science
Replies
22
Views
730
  • Engineering and Comp Sci Homework Help
Replies
32
Views
3K
Replies
13
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
1K
Replies
7
Views
1K
Replies
6
Views
816
  • Linear and Abstract Algebra
Replies
4
Views
3K
  • Linear and Abstract Algebra
Replies
6
Views
3K
  • General Math
Replies
12
Views
954
  • General Math
Replies
19
Views
2K
Back
Top