DIVCOUNT

This function returns the number of positive divisors of an integer, with optional filtering by a modulus and optional exclusion of the number itself.

For an integer n, the divisor count function is often written as d(n) and counts values k such that k \mid n.

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

When a modulus is provided, only divisors divisible by that modulus are counted, and proper mode excludes n itself.

Excel Usage

=DIVCOUNT(n, modulus, proper)
  • n (int, required): Integer whose divisors are counted.
  • modulus (int, optional, default: 1): Divisor must be divisible by this value.
  • proper (bool, optional, default: false): Whether to exclude n itself from the count.

Returns (int): Number of matching divisors.

Example 1: Divisor count of twenty four

Inputs:

n modulus proper
24 1 false

Excel formula:

=DIVCOUNT(24, 1, FALSE)

Expected output:

8

Example 2: Divisor count with divisibility filter

Inputs:

n modulus proper
24 2 false

Excel formula:

=DIVCOUNT(24, 2, FALSE)

Expected output:

6

Example 3: Proper divisor count excludes the integer itself

Inputs:

n modulus proper
24 1 true

Excel formula:

=DIVCOUNT(24, 1, TRUE)

Expected output:

7

Example 4: Divisor count of a prime integer

Inputs:

n modulus proper
29 1 false

Excel formula:

=DIVCOUNT(29, 1, FALSE)

Expected output:

2

Python Code

from sympy import divisor_count as sympy_divisor_count

def divcount(n, modulus=1, proper=False):
    """
    Count divisors of an integer with optional modulus filtering.

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

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

    Args:
        n (int): Integer whose divisors are counted.
        modulus (int, optional): Divisor must be divisible by this value. Default is 1.
        proper (bool, optional): Whether to exclude n itself from the count. Default is False.

    Returns:
        int: Number of matching divisors.
    """
    try:
        if isinstance(n, bool) or isinstance(modulus, bool):
            return "Error: n and modulus must be integers"

        n_value = int(n)
        modulus_value = int(modulus)

        if float(n) != float(n_value) or float(modulus) != float(modulus_value):
            return "Error: n and modulus must be integers"
        if modulus_value == 0:
            return "Error: modulus must be nonzero"

        return int(sympy_divisor_count(n_value, modulus=modulus_value, proper=proper))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Integer whose divisors are counted.
Divisor must be divisible by this value.
Whether to exclude n itself from the count.