PROPDIVCNT

This function returns the number of proper divisors of an integer.

Proper divisors are positive divisors strictly less than the number itself.

d_{\text{proper}}(n) = \#\{k \in \mathbb{N} : k \mid n,\ k < n\}

A modulus filter can be applied so only proper divisors divisible by that modulus are counted.

Excel Usage

=PROPDIVCNT(n, modulus)
  • n (int, required): Integer whose proper divisors are counted.
  • modulus (int, optional, default: 1): Proper divisor must be divisible by this value.

Returns (int): Number of proper divisors matching the filter.

Example 1: Proper divisor count of twenty four

Inputs:

n modulus
24 1

Excel formula:

=PROPDIVCNT(24, 1)

Expected output:

7

Example 2: Proper divisor count with divisibility filter

Inputs:

n modulus
24 2

Excel formula:

=PROPDIVCNT(24, 2)

Expected output:

5

Example 3: Proper divisor count of a prime integer

Inputs:

n modulus
13 1

Excel formula:

=PROPDIVCNT(13, 1)

Expected output:

1

Example 4: Proper divisor count of one

Inputs:

n modulus
1 1

Excel formula:

=PROPDIVCNT(1, 1)

Expected output:

0

Python Code

from sympy import proper_divisor_count as sympy_proper_divisor_count

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

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

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

    Args:
        n (int): Integer whose proper divisors are counted.
        modulus (int, optional): Proper divisor must be divisible by this value. Default is 1.

    Returns:
        int: Number of proper divisors matching the filter.
    """
    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_proper_divisor_count(n_value, modulus=modulus_value))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Integer whose proper divisors are counted.
Proper divisor must be divisible by this value.