DIVISORS

This function returns all positive divisors of an integer as a sorted one-column table.

The divisor set of n is:

D(n) = \{d \in \mathbb{N} : d \mid n\}

When proper mode is enabled, the number itself is excluded from the returned set.

Excel Usage

=DIVISORS(n, proper)
  • n (int, required): Integer whose divisors are listed.
  • proper (bool, optional, default: false): Whether to exclude n itself from the list.

Returns (list[list]): One-column 2D array of divisors in ascending order.

Example 1: Divisors of twenty four

Inputs:

n proper
24 false

Excel formula:

=DIVISORS(24, FALSE)

Expected output:

Result
1
2
3
4
6
8
12
24
Example 2: Proper divisors of twenty four

Inputs:

n proper
24 true

Excel formula:

=DIVISORS(24, TRUE)

Expected output:

Result
1
2
3
4
6
8
12
Example 3: Divisors of a prime integer

Inputs:

n proper
13 false

Excel formula:

=DIVISORS(13, FALSE)

Expected output:

Result
1
13
Example 4: Divisors of one

Inputs:

n proper
1 false

Excel formula:

=DIVISORS(1, FALSE)

Expected output:

1

Python Code

from sympy import divisors as sympy_divisors

def divisors(n, proper=False):
    """
    List divisors of an integer with optional proper divisor mode.

    See: https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.factor_.divisors

    This example function is provided as-is without any representation of accuracy.

    Args:
        n (int): Integer whose divisors are listed.
        proper (bool, optional): Whether to exclude n itself from the list. Default is False.

    Returns:
        list[list]: One-column 2D array of divisors in ascending order.
    """
    try:
        if isinstance(n, bool):
            return "Error: n must be an integer"

        n_value = int(n)
        if float(n) != float(n_value):
            return "Error: n must be an integer"

        values = sympy_divisors(n_value, generator=False, proper=proper)
        return [[int(value)] for value in values]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Integer whose divisors are listed.
Whether to exclude n itself from the list.