FBB::PrimeFactors(3bobcat) Prime Factorization FBB::PrimeFactors(3bobcat) NAME FBB::PrimeFactors - Performs the prime-number factorization of (BigInt) values SYNOPSIS #include Linking option: -lbobcat DESCRIPTION Integral values fall into two categories: prime numbers, whose only integral divisors are their own values and 1, and composite numbers, which also have at least one other (prime number) integral divisor. All composite integral values can be factorized as the product of prime numbers. E.g., 6 can be factorized as 2 * 3; 8 can be factorized as 2 * 2 * 2. Finding these prime factors is called the prime number factorization, or `prime factorization'. When factorizing a value its prime factors may sometimes repeatedly be used as integral divisors: 8 is factorized as pow(2, 3), and 36 is factorized as 36 = pow(2, 2) * pow(3, 2) The class FBB::PrimeFactors performs prime number factorizations of FBB::BigInt values. When factorizing a value prime numbers up to sqrt(value) must be available, as prime numbers up to sqrt(value) may be factors of value. Currently PrimeFactors uses the sieve of Eratosthenes to find these prime numbers. To find the next prime number beyond lastPrime, the sieve of Eratosthenes must be used repeatedly for lastPrime += 2 until lastPrime is prime. Once determined, prime numbers can of course be used directly to determine the next prime number or to factorize an integral value. To accellerate prime number factorization and Eratosthenes's sieve PrimeFactors saves all its computed prime numbers in either a std::vector or in a file. Once determined, these prime numbers may again be used when factorizing the next integral value. After factorizing an integral value its prime number factors and associated powers are made available in a vector of (PrimeFactors::PrimePower) structs, containing the value's sorted prime factors and associated powers. NAMESPACE FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM - TYPEDEFS AND ENUMS o struct PrimePower: contains two fields: struct PrimePower { BigInt prime; size_t power; }; Here, power represents the number of times prime can be used as an integral divisor of the value that was factorized by PrimeFactors. o Factors: is a synonym for std::vector #include using namespace std; using namespace FBB; int main(int argc, char **argv) { PrimeFactors pf1("/tmp/primes"); PrimeFactors::Factors const *factors = &pf1.factorize(stoull(argv[1])); cout << "Using /tmp/primes:\n"; for (auto &factor: *factors) cout << factor.prime << "**" << factor.power << ' '; vector primes; PrimeFactors pf2(primes); factors = &pf2.factorize(stoull(argv[1])); cout << "\n" "Using BigIntVector:\n"; for (auto &factor: *factors) cout << factor.prime << "**" << factor.power << ' '; cout << "\n" "Collected primes: "; for (auto &prime: primes) cout << prime << ' '; cout << '\n'; } If this program is run with argument 1950 it produces the following output: Using /tmp/primes: 2**1 3**1 5**2 13**1 Using BigIntVector: 2**1 3**1 5**2 13**1 Collected primes: 2 3 5 7 11 13 FILES bobcat/primefactors - defines the class interface SEE ALSO bobcat(7), bigint(3bobcat) BUGS None Reported. BOBCAT PROJECT FILES o https://fbb-git.gitlab.io/bobcat/: gitlab project page; o bobcat_6.06.02-x.dsc: detached signature; o bobcat_6.06.02-x.tar.gz: source archive; o bobcat_6.06.02-x_i386.changes: change log; o libbobcat1_6.06.02-x_*.deb: debian package containing the libraries; o libbobcat1-dev_6.06.02-x_*.deb: debian package containing the libraries, headers and manual pages; BOBCAT Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR Frank B. Brokken (f.b.brokken@rug.nl). libbobcat-dev_6.06.02 2005-2024 FBB::PrimeFactors(3bobcat)