galois.trial_division(n: int, B: int | None = None) tuple[list[int], list[int], int]

Finds all the prime factors piei of n for piB.

The trial division factorization will find all prime factors piB such that n factors as n=p1e1pkeknr where nr is a residual factor (which may be composite).

Parameters:
n: int

A positive integer.

B: int | None = None

The max divisor in the trial division. The default is None which corresponds to B=n. If B>n, the algorithm will only search up to n, since a prime factor of n cannot be larger than n.

Returns:

  • The discovered prime factors {p1,,pk}.

  • The corresponding prime exponents {e1,,ek}.

  • The residual factor nr.

See also

factors

Examples

In [1]: n = 2**4 * 17**3 * 113 * 15013

In [2]: galois.trial_division(n)
Out[2]: ([2, 17, 113, 15013], [4, 3, 1, 1], 1)

In [3]: galois.trial_division(n, B=500)
Out[3]: ([2, 17, 113], [4, 3, 1], 15013)

In [4]: galois.trial_division(n, B=100)
Out[4]: ([2, 17], [4, 3], 1696469)