An Algorithm to find a Prime Decompisition

In summary, the conversation discusses a method for finding the prime decomposition of a number, specifically in relation to large numbers. While there is no quick algorithm for factorizing large numbers, there are some techniques that can make the process a little faster. These include only going up to the square root of the number and using the formula m/p_n = int(m/p_n) to check for factors. However, even with these techniques, factorizing very large numbers remains a challenging task.
  • #1
Chu
10
0
Hello all. I know there is a stupidly easy algorithm to find the prime decompision of a number (i.e. 2*2*2*3*5 is the p.d. of 120) but I can't for the life of me remember it. I need to do this operation on incredibly large numbers (~500 digits) so the naieve way of just starting at 2 and proceding through the primes *PROBABLY* doesn't work (if it does -- please tell me!) but I know there is a less naieve but still simplistic algorithm. Anyone out there know it?

-Chu
 
Physics news on Phys.org
  • #2
I'm sorry to say but there isn't a quick way to do it. Factorising large numbers quickly is one of the holy grails of number theory.

There are however obvious things you can do to make it a little quicker. Where m is your number and p_n is a prime you are dividing by there are a couple of things to remember when making an algorithm. You only need to go up to the square root of m by default. Your general line is does m/p_n = int(m/p_n)? If yes try it again and if no move on to the next prime. Also if yes you can set the maximum number you need to check up to as squareroot(m)/p_n.

There may be a faster way I am not aware of but it still won't be able to deal with very big numbers quickly. For example the MATLAB factor command only allows a limit of numbers as big as 2^32
 
  • #3


Hello Chu,

Thank you for your question. Fortunately, there is a well-known algorithm for finding the prime decomposition of a number, called the "trial division" method. This method involves dividing the number by smaller prime numbers until it can no longer be divided any further. The resulting factors will be the prime decomposition.

To use this method for large numbers, it is important to use a list of prime numbers instead of checking every number starting from 2. This can be done by generating a list of prime numbers using the Sieve of Eratosthenes or by using a pre-existing list.

Here is an example of the trial division method in action:

Let's find the prime decomposition of 120.

Step 1: Start with the smallest prime number, 2. Divide 120 by 2, which gives 60. The factors so far are 2 and 60.

Step 2: Continue dividing by 2 until it can no longer be divided. 60 divided by 2 gives 30. The factors so far are 2, 2, and 30.

Step 3: Now, move on to the next prime number, 3. Divide 30 by 3, which gives 10. The factors so far are 2, 2, 3, and 10.

Step 4: Divide 10 by 2, which gives 5. The factors so far are 2, 2, 3, 2, and 5.

Step 5: Since 5 is a prime number, we can stop here. The final prime decomposition of 120 is 2 * 2 * 2 * 3 * 5.

This method is efficient for large numbers, but it may still take some time for numbers with hundreds of digits. In that case, there are more advanced algorithms that can be used, such as the Pollard's rho algorithm or the elliptic curve factorization method.

I hope this helps. Good luck with your calculations!
 

1. What is an algorithm for finding a prime decomposition?

An algorithm for finding a prime decomposition is a step-by-step process that breaks down a number into its prime factors. This is useful in many mathematical applications, such as simplifying fractions or finding the greatest common divisor.

2. How does the algorithm work?

The algorithm works by dividing the given number by the smallest prime number possible, then repeating the process with the resulting quotient until the quotient is 1. The prime factors used in the division are recorded and then multiplied together to get the prime decomposition of the original number.

3. Can I use this algorithm for any number?

Yes, this algorithm can be used for any positive integer. However, the larger the number, the longer it may take to find the prime decomposition.

4. Are there any limitations to this algorithm?

One limitation is that it only works for positive integers. It also may not be the most efficient algorithm for finding prime decompositions of very large numbers.

5. How is this algorithm useful in real-world applications?

Finding prime decompositions is useful in many mathematical and scientific fields, such as cryptography, number theory, and physics. It can also be used in computer programming to optimize code or find patterns in data.

Similar threads

  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
532
  • Linear and Abstract Algebra
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
952
  • Programming and Computer Science
Replies
8
Views
1K
  • Linear and Abstract Algebra
Replies
6
Views
3K
  • Programming and Computer Science
2
Replies
46
Views
4K
  • Quantum Physics
Replies
1
Views
810
  • General Discussion
Replies
4
Views
2K
Back
Top