FACTORINT
This function decomposes an integer into prime factors and their exponents.
For a nonzero integer n, the factorization is represented as:
n = \prod_{k=1}^{m} p_k^{e_k}
where each p_k is prime and each e_k is a positive integer. The output is a 2D table with one row per factor.
Excel Usage
=FACTORINT(n, limit, use_trial, use_rho, use_pm_one, use_ecm, verbose)
n(int, required): Integer to factor.limit(int, optional, default: null): Optional trial factorization limit.use_trial(bool, optional, default: true): Whether to use trial division.use_rho(bool, optional, default: true): Whether to use Pollard rho factor search.use_pm_one(bool, optional, default: true): Whether to use Pollard p minus 1 method.use_ecm(bool, optional, default: true): Whether to use elliptic curve method steps.verbose(bool, optional, default: false): Whether to print verbose factorization progress.
Returns (list[list]): Two-column 2D array of [prime_factor, exponent] rows.
Example 1: Factorization of sixty
Inputs:
| n | limit | use_trial | use_rho | use_pm_one | use_ecm | verbose |
|---|---|---|---|---|---|---|
| 60 | true | true | true | true | false |
Excel formula:
=FACTORINT(60, , TRUE, TRUE, TRUE, TRUE, FALSE)
Expected output:
| Result | |
|---|---|
| 2 | 2 |
| 3 | 1 |
| 5 | 1 |
Example 2: Factorization of a prime integer
Inputs:
| n | limit | use_trial | use_rho | use_pm_one | use_ecm | verbose |
|---|---|---|---|---|---|---|
| 97 | true | true | true | true | false |
Excel formula:
=FACTORINT(97, , TRUE, TRUE, TRUE, TRUE, FALSE)
Expected output:
| Result | |
|---|---|
| 97 | 1 |
Example 3: Factorization of one thousand two hundred sixty
Inputs:
| n | limit | use_trial | use_rho | use_pm_one | use_ecm | verbose |
|---|---|---|---|---|---|---|
| 1260 | true | true | true | true | false |
Excel formula:
=FACTORINT(1260, , TRUE, TRUE, TRUE, TRUE, FALSE)
Expected output:
| Result | |
|---|---|
| 2 | 2 |
| 3 | 2 |
| 5 | 1 |
| 7 | 1 |
Example 4: Factorization including sign for negative input
Inputs:
| n | limit | use_trial | use_rho | use_pm_one | use_ecm | verbose |
|---|---|---|---|---|---|---|
| -84 | true | true | true | true | false |
Excel formula:
=FACTORINT(-84, , TRUE, TRUE, TRUE, TRUE, FALSE)
Expected output:
| Result | |
|---|---|
| -1 | 1 |
| 2 | 2 |
| 3 | 1 |
| 7 | 1 |
Python Code
from sympy import factorint as sympy_factorint
def factorint(n, limit=None, use_trial=True, use_rho=True, use_pm_one=True, use_ecm=True, verbose=False):
"""
Compute the prime factorization of an integer with multiplicities.
See: https://docs.sympy.org/latest/modules/ntheory.html
This example function is provided as-is without any representation of accuracy.
Args:
n (int): Integer to factor.
limit (int, optional): Optional trial factorization limit. Default is None.
use_trial (bool, optional): Whether to use trial division. Default is True.
use_rho (bool, optional): Whether to use Pollard rho factor search. Default is True.
use_pm_one (bool, optional): Whether to use Pollard p minus 1 method. Default is True.
use_ecm (bool, optional): Whether to use elliptic curve method steps. Default is True.
verbose (bool, optional): Whether to print verbose factorization progress. Default is False.
Returns:
list[list]: Two-column 2D array of [prime_factor, exponent] rows.
"""
try:
factors = sympy_factorint(
n,
limit=limit,
use_trial=use_trial,
use_rho=use_rho,
use_pm1=use_pm_one,
use_ecm=use_ecm,
verbose=verbose,
visual=False,
multiple=False,
)
rows = []
for factor, exponent in sorted(factors.items(), key=lambda item: int(item[0])):
rows.append([int(factor), int(exponent)])
return rows
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Integer to factor.
Optional trial factorization limit.
Whether to use trial division.
Whether to use Pollard rho factor search.
Whether to use Pollard p minus 1 method.
Whether to use elliptic curve method steps.
Whether to print verbose factorization progress.