C# Класс Crisis.SmallPrimeUtility

Utility class that maintains a small table of prime numbers and provides simple implementations of Prime Factorization algorithms. This is a quick and dirty utility class to support calculations of permutation sets with indexes under 2^31. The prime table contains all primes up to Sqrt(2^31) which are all of the primes requires to factorize any Int32 positive integer.
Показать файл Открыть проект

Открытые методы

Метод Описание
DividePrimeFactors ( IList numerator, IList denominator ) : List

Given two integers expressed as a list of prime factors, divides these numbers and returns an integer also expressed as a set of prime factors. If the result is not a integer, then the result is undefined. That is, 11 / 5 when divided by this function will not yield a correct result. As such, this function is ONLY useful for division with combinatorial results where the result is known to be an integer AND the division occurs as the last operation(s).

EvaluatePrimeFactors ( IList value ) : long

Given a list of prime factors returns the long representation.

Factor ( int i ) : List

Performs a prime factorization of a given integer using the table of primes in PrimeTable. Since this will only factor Int32 sized integers, a simple list of factors is returned instead of the more scalable, but more difficult to consume, list of primes and associated exponents.

MultiplyPrimeFactors ( IList lhs, IList rhs ) : List

Given two integers expressed as a list of prime factors, multiplies these numbers together and returns an integer also expressed as a set of prime factors. This allows multiplication to overflow well beyond a Int64 if necessary.

Приватные методы

Метод Описание
CalculatePrimes ( ) : void

Calculate all primes up to Sqrt(2^32) = 2^16. This table will be large enough for all factorizations for Int32's. Small tables are best built using the Sieve Of Eratosthenes, Reference: http://primes.utm.edu/glossary/page.php?sort=SieveOfEratosthenes

SmallPrimeUtility ( ) : System.Collections.Generic

Utility class, no instances allowed.

Описание методов

DividePrimeFactors() публичный статический Метод

Given two integers expressed as a list of prime factors, divides these numbers and returns an integer also expressed as a set of prime factors. If the result is not a integer, then the result is undefined. That is, 11 / 5 when divided by this function will not yield a correct result. As such, this function is ONLY useful for division with combinatorial results where the result is known to be an integer AND the division occurs as the last operation(s).
public static DividePrimeFactors ( IList numerator, IList denominator ) : List
numerator IList Numerator argument, expressed as list of prime factors.
denominator IList Denominator argument, expressed as list of prime factors.
Результат List

EvaluatePrimeFactors() публичный статический Метод

Given a list of prime factors returns the long representation.
public static EvaluatePrimeFactors ( IList value ) : long
value IList Integer, expressed as list of prime factors.
Результат long

Factor() публичный статический Метод

Performs a prime factorization of a given integer using the table of primes in PrimeTable. Since this will only factor Int32 sized integers, a simple list of factors is returned instead of the more scalable, but more difficult to consume, list of primes and associated exponents.
public static Factor ( int i ) : List
i int The number to factorize, must be positive.
Результат List

MultiplyPrimeFactors() публичный статический Метод

Given two integers expressed as a list of prime factors, multiplies these numbers together and returns an integer also expressed as a set of prime factors. This allows multiplication to overflow well beyond a Int64 if necessary.
public static MultiplyPrimeFactors ( IList lhs, IList rhs ) : List
lhs IList Left Hand Side argument, expressed as list of prime factors.
rhs IList Right Hand Side argument, expressed as list of prime factors.
Результат List