PRIMEFACTORS

This function returns the set of prime divisors of an integer, sorted in ascending order and without multiplicities.

If the full prime-power factorization is n = \prod p_k^{e_k}, this function returns only the distinct primes \{p_k\}.

The output is provided as a single-column 2D array for Excel compatibility.

Excel Usage

=PRIMEFACTORS(n, limit, verbose)
  • n (int, required): Integer whose prime divisors are requested.
  • limit (int, optional, default: null): Optional factorization limit for partial search.
  • verbose (bool, optional, default: false): Whether to show detailed factorization progress.

Returns (list[list]): Single-column 2D array of distinct prime factors.

Example 1: Distinct prime factors of six

Inputs:

n limit verbose
6 false

Excel formula:

=PRIMEFACTORS(6, , FALSE)

Expected output:

Result
2
3
Example 2: Distinct prime factors of one hundred twenty three thousand four hundred fifty six

Inputs:

n limit verbose
123456 false

Excel formula:

=PRIMEFACTORS(123456, , FALSE)

Expected output:

Result
2
3
643
Example 3: Distinct prime factors of negative number

Inputs:

n limit verbose
-84 false

Excel formula:

=PRIMEFACTORS(-84, , FALSE)

Expected output:

Result
2
3
7
Example 4: Distinct prime factors of a prime input

Inputs:

n limit verbose
101 false

Excel formula:

=PRIMEFACTORS(101, , FALSE)

Expected output:

101

Python Code

from sympy import primefactors as sympy_primefactors

def primefactors(n, limit=None, verbose=False):
    """
    Return distinct prime factors of an integer.

    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 whose prime divisors are requested.
        limit (int, optional): Optional factorization limit for partial search. Default is None.
        verbose (bool, optional): Whether to show detailed factorization progress. Default is False.

    Returns:
        list[list]: Single-column 2D array of distinct prime factors.
    """
    try:
        values = sympy_primefactors(n, limit=limit, verbose=verbose)
        return [[int(v)] for v in values]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Integer whose prime divisors are requested.
Optional factorization limit for partial search.
Whether to show detailed factorization progress.