Tool to decompose a number into a product of prime factors (any size, no limit), decomposition as a multiplication of prime numbers that is unique for all integers.
Prime Factors Decomposition - dCode
Tag(s) : Arithmetics
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
In Mathematics, the prime factors decomposition (also known as Prime Integer Factorization) consists in writing a positive integer with a product of prime factors.
This factorization is unique and exists for all numbers and has many applications, especially in cryptography.
To find the prime factorization of a number $ N $ there is no mathematical formula. To achieve this, there are algorithms including the most basic that attempt to divide the number $ N $ by all prime factors $ p $ which are less than $ N $. If $ p $ is a divisor of $ N $ then start again by taking a new $ N = N/p $ as long as there are any possible divisors.
Example: If $ N = 147 $, the prime numbers that are less than $ N = 147 $ are $ 2, 3, 5, 7, 11, 13, … $. The prime factorisation algorithm for $ 147 $, begins by attempting the division by $ 2 $, $ 147 $ is not divisible by $ 2 $. Then divide by $ 3 $, $ 147/3 = 49 $ so $ 147 $ is divisible by $ 3 $ and $ 3 $ is a prime factor of $ 147 $. Then, no longer take $ 147 $ but $ 147/3 = 49 $. The prime numbers less than $ 49 $ are $ 2, 3, 5, 7, 11, 13, … $, try to divide $ 49 $ by $ 2 $ and so on.
Example: Finally, it remains the factors $ 3, 7, 7 $ and check that $ 3 \times 7 \times 7 = 147 $, or write $ 147 = 3 \times 7 ^ 2 $ (the exponent avoids repetition).
This decomposition is possible whatever the starting number, it is a fundamental theorem of arithmetic.
Example: $ 123 = 3 \times 41 $, $ 1234 = 2 \times 617 $, $ 12345 = 3 \times 5 \times 823 $ or $ 123456 = 2 ^ 6 \times 3 \times 643 $
The problem with prime number decomposition methods (or algorithms) is that they are very long when the numbers are very large. As soon as the factors have several dozen digits and are not trivial, several minutes or even hours or even days of calculations can be necessary, even for the most powerful computers.
The RSA Factoring Challenge is a list of large semi-prime numbers (the product of two large prime numbers) to factor with several thousand dollars at stake, the 'RSA-100' (a 100-digit integer) was factored in a few days, the 'RSA-250' (a 250-digit integer) was factored after several years of intensive calculation.
The duration of the calculation is not predictable, but the calculation time required to decompose cryptographic numbers of several hundred digits is measured in thousands of core-years (amount of work that a single processor core can accomplish in an entire year: 365 days, 24 hours per day of continuous calculation).
dCode performs the calculations on the server side as possible, but if the requested number has too many digits, the calculation will continue on your browser thanks to a WebAssembly applet (wasm) by Dario Alejandro Alpern (License GPL v3.0) the calculation time will therefore depend on the performance of your computer/phone.
There exists several factorization algorithms: classical iterative division, Pollard rho algorithm, elliptic curves, and the quadratic sieve algorithm. dCode uses a combination of all them to fast factorize.
The whole list of prime numbers starts with: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997… and there are an infinite number of primes.
Prime numbers are defined only among natural numbers, that is, positive numbers (not negative prime numbers).
The demonstration of the infinity of prime numbers is:
If there exists $ p $, a finite number of prime numbers, so it exists $ p\# = 2 \times 3 \times 5 \times \cdots $ the product of the list of all these prime numbers (sometimes called the primorial).
Let $ q = p\#+1 $, then, this number is not divisible by any prime factor of the list because the remainder of the division of $ q $ by any prime number of the list will be equal to $ 1 $.
Therefore $ q $ is a new prime number or has a prime factor not present in the list, which contradicts the hypothesis.
Therefore, there will always exist prime numbers greater than $ p\# $ whatever $ p $, so there are an infinity of them.
// javascript
function prime_factors(n) {
if (!n || n < 2)
return [];
var factors = [];
for (var i = 2; i <= n; i++){
while (n % i === 0){
factors.push(i);
n /= i;
}
}
return factors;
};
// Python
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
dCode retains ownership of the "Prime Factors Decomposition" source code. Except explicit open source licence (indicated Creative Commons / free), the "Prime Factors Decomposition" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or the "Prime Factors Decomposition" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, or API access for "Prime Factors Decomposition" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app!
Reminder : dCode is free to use.
The copy-paste of the page "Prime Factors Decomposition" or any of its results, is allowed (even for commercial purposes) as long as you credit dCode!
Exporting results as a .csv or .txt file is free by clicking on the export icon
Cite as source (bibliography):
Prime Factors Decomposition on dCode.fr [online website], retrieved on 2024-12-21,