FiSGO.PrimesHandler.factor
- factor(n, primes_path='/home/docs/checkouts/readthedocs.org/user_builds/fisgo/checkouts/latest/FiSGO/PrecomputedData/BuiltinPrimes.txt', list_output=False)[source]
- Given an integer n, it attempts to find the prime factors of n. Returns a tuple:
[0] - dictionary with prime:power entries
[1] - leftover factor
A number has been successfully factorized if the leftover factor is 1. Otherwise, the leftover factor contains all prime factors not contained in the list in primes_path.
File primes_path is specified to PRIMES_PATH by default, containing 10^5 first primes; primes_path should refer to a file where each line contains a single prime number, in ascending order, see PRIMES_PATH for an example of the required format.
- Parameters:
n (
int) – Integer. Number to be factorized.primes_path – String, path to a file with an ordered list of prime numbers.
list_output – Boolean, if True, the function returns a list of the exponents, otherwise, returns a dictionary whose keys are prime numbers and values their associated exponents. By default, set to False.
- Return type:
- Returns:
Tuple containing a list or dictionary of integers and an integer. The first contains the exponents of prime powers dividing n. The integer contains the leftover factor if not enough primes are available for a complete factorization. The first object of the tuple is a list if list_output is set to True, otherwise it returns a dictionary whose keys are prime numbers and values their associated exponents.