Calculates the decomposition of a positive integer into primes.
Use the following HTML code to embed the calculators within other websites:
Factorize Direct
std::vector<factor>factorize_direct(
unsigned
n
)
This functions calculates the unique factorization of a positive number into a product of primes raised to different
powers. It uses the Maths/NumberTheory/Primes function to directly find a prime number and test the division of n against it. This
proves to be faster than the other prime decomposition function; the only limitation is the maximum number of
primes stored within the Maths/NumberTheory/Primes component.
Warning
While using this component, one cannot also include the Maths/NumberTheory/Factorize component. This will generate a
compiler error.
Example:
#include <codecogs/maths/discrete/number_theory/factorize_direct.h>#include <iostream>int main(){
std::vector<factor> result = Maths::NumberTheory::factorize_direct(65435);
std::cout << "The factorization of 65435 into primes is" << std::endl;
for(int i = 0; i < result.size(); i++)
std::cout << result[i].value << "^" << result[i].power << " ";
std::cout << std::endl;
return0;
}
Output:
The factorization of 65435 into primes is
5^123^1569^1