Gcd Lcm Divisors

Overview

Greatest common divisors, least common multiples, divisor sets, and totient functions are core tools in elementary number theory. They describe how integers factor, how cycles behave under modular arithmetic, and how arithmetic constraints combine across multiple inputs. In data analysis and engineering workflows, these ideas appear in period alignment, hashing/modulus logic, scheduling, cryptography, and algorithm design.

At a conceptual level, this category combines two families of operations: factor-structure queries (counting or listing divisors) and coprimality/modular-group queries (totient-style functions). The structural side asks what divides n and in what quantity; the modular side asks how many residues are invertible mod n and what exponent controls their behavior. The pair of identities \gcd(a,b)\cdot\operatorname{lcm}(a,b)=|ab| and \varphi(n)=n\prod_{p\mid n}(1-1/p) highlights how prime factors connect these views.

Implementations here are built on Python’s standard math module, SymPy number theory utilities, and primePy. The math functions provide fast integer primitives, SymPy provides symbolic and exact number-theory routines, and primePy contributes an alternative totient implementation. Together, they expose reliable building blocks for spreadsheet-style number-theory workflows.

GCD, LCM, and ISQRT provide foundational integer operations for normalization and scale management. GCD computes the largest shared divisor across one or many integers, while LCM computes the smallest shared multiple used to synchronize periodic processes. ISQRT returns \lfloor\sqrt{n}\rfloor, which is a common bound in factor-search and primality-related routines. In practice, these functions are frequently paired when reducing fractions, aligning sample windows, or validating divisibility constraints.

DIVISORS, PROPDIVS, DIVCOUNT, and PROPDIVCNT focus on explicit divisor structure. DIVISORS and PROPDIVS return full sorted divisor sets (including or excluding n), while DIVCOUNT and PROPDIVCNT return counts, optionally filtered by a modulus condition. This split between listing and counting supports both exploratory checks and efficient feature engineering. Typical use cases include detecting highly composite numbers, constructing factor-based heuristics, and enforcing rule-based eligibility conditions.

TOTIENT, PPY_PHI, and REDUCEDTOT cover multiplicative-group behavior modulo n. TOTIENT and PPY_PHI both evaluate Euler’s totient \varphi(n) through different libraries, which is useful for cross-checking and compatibility. REDUCEDTOT evaluates Carmichael’s function \lambda(n), the smallest exponent that sends every unit modulo n to 1. These functions are central in modular arithmetic diagnostics, order/cycle analysis, and cryptographic parameter intuition.

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

Show 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.

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

Show 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.

GCD

This function computes the greatest common divisor (GCD) of a set of integers.

For integers a_1, a_2, \dots, a_k, the GCD is the largest positive integer d such that d divides each input exactly.

\gcd(a_1, a_2, \dots, a_k) = \max\{d \in \mathbb{N} : d \mid a_i\ \forall i\}

The function accepts a scalar or 2D range and uses all valid integer values found in the input.

Excel Usage

=GCD(integers)
  • integers (list[list], required): 2D array of integers to combine.

Returns (int): Greatest common divisor of the input integers.

Example 1: Greatest common divisor of three integers

Inputs:

integers
24 36 60

Excel formula:

=GCD({24,36,60})

Expected output:

12

Example 2: Greatest common divisor with negative input

Inputs:

integers
-27 36 45

Excel formula:

=GCD({-27,36,45})

Expected output:

9

Example 3: Greatest common divisor for scalar input

Inputs:

integers
42

Excel formula:

=GCD(42)

Expected output:

42

Example 4: Greatest common divisor from mixed 2D range

Inputs:

integers
18 x
30 48

Excel formula:

=GCD({18,"x";30,48})

Expected output:

6

Python Code

Show Code
from math import gcd as math_gcd

def gcd(integers):
    """
    Compute the greatest common divisor of one or more integers.

    See: https://docs.python.org/3/library/math.html#math.gcd

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

    Args:
        integers (list[list]): 2D array of integers to combine.

    Returns:
        int: Greatest common divisor of the input integers.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        values_2d = to2d(integers)
        if not isinstance(values_2d, list) or not all(isinstance(row, list) for row in values_2d):
            return "Error: Invalid input - integers must be a 2D list or scalar"

        flat_values = []
        for row in values_2d:
            for value in row:
                if isinstance(value, bool):
                    continue
                try:
                    parsed = int(value)
                    if float(value) == float(parsed):
                        flat_values.append(parsed)
                except Exception:
                    continue

        if not flat_values:
            return "Error: Input must contain at least one integer"

        result = flat_values[0]
        for value in flat_values[1:]:
            result = math_gcd(result, value)

        return int(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

2D array of integers to combine.

ISQRT

This function returns the integer square root of a nonnegative integer.

The integer square root is the floor of the exact square root:

\operatorname{isqrt}(n) = \left\lfloor \sqrt{n} \right\rfloor

It is the greatest integer r such that r^2 \le n.

Excel Usage

=ISQRT(n)
  • n (int, required): Nonnegative integer input.

Returns (int): Largest integer whose square is less than or equal to the input.

Example 1: Integer square root of perfect square

Inputs:

n
144

Excel formula:

=ISQRT(144)

Expected output:

12

Example 2: Integer square root rounds down for non-square

Inputs:

n
200

Excel formula:

=ISQRT(200)

Expected output:

14

Example 3: Integer square root of zero

Inputs:

n
0

Excel formula:

=ISQRT(0)

Expected output:

0

Example 4: Integer square root of a large integer

Inputs:

n
123456789

Excel formula:

=ISQRT(123456789)

Expected output:

11111

Python Code

Show Code
from math import isqrt as math_isqrt

def isqrt(n):
    """
    Compute the integer square root of a nonnegative integer.

    See: https://docs.python.org/3/library/math.html#math.isqrt

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

    Args:
        n (int): Nonnegative integer input.

    Returns:
        int: Largest integer whose square is less than or equal to the input.
    """
    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"
        if n_value < 0:
            return "Error: n must be nonnegative"

        return int(math_isqrt(n_value))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Nonnegative integer input.

LCM

This function computes the least common multiple (LCM) of a set of integers.

For integers a_1, a_2, \dots, a_k, the LCM is the smallest positive integer that is divisible by each input.

\operatorname{lcm}(a_1, a_2, \dots, a_k) = \min\{m \in \mathbb{N} : a_i \mid m\ \forall i\}

The function accepts a scalar or 2D range and uses all valid integer values found in the input.

Excel Usage

=LCM(integers)
  • integers (list[list], required): 2D array of integers to combine.

Returns (int): Least common multiple of the input integers.

Example 1: Least common multiple of three integers

Inputs:

integers
6 8 9

Excel formula:

=LCM({6,8,9})

Expected output:

72

Example 2: Least common multiple with zero included

Inputs:

integers
5 0 10

Excel formula:

=LCM({5,0,10})

Expected output:

0

Example 3: Least common multiple for scalar input

Inputs:

integers
15

Excel formula:

=LCM(15)

Expected output:

15

Example 4: Least common multiple from mixed 2D range

Inputs:

integers
4 x
10 20

Excel formula:

=LCM({4,"x";10,20})

Expected output:

20

Python Code

Show Code
from math import lcm as math_lcm

def lcm(integers):
    """
    Compute the least common multiple of one or more integers.

    See: https://docs.python.org/3/library/math.html#math.lcm

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

    Args:
        integers (list[list]): 2D array of integers to combine.

    Returns:
        int: Least common multiple of the input integers.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        values_2d = to2d(integers)
        if not isinstance(values_2d, list) or not all(isinstance(row, list) for row in values_2d):
            return "Error: Invalid input - integers must be a 2D list or scalar"

        flat_values = []
        for row in values_2d:
            for value in row:
                if isinstance(value, bool):
                    continue
                try:
                    parsed = int(value)
                    if float(value) == float(parsed):
                        flat_values.append(parsed)
                except Exception:
                    continue

        if not flat_values:
            return "Error: Input must contain at least one integer"

        result = flat_values[0]
        for value in flat_values[1:]:
            result = math_lcm(result, value)

        return int(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

2D array of integers to combine.

PPY_PHI

This function computes Euler’s totient function using primePy.

The totient function counts how many positive integers up to n are relatively prime to n:

\varphi(n) = \#\{k \in \mathbb{N} : 1 \le k \le n,\ \gcd(k, n) = 1\}

This provides an alternative implementation path for totient calculations.

Excel Usage

=PPY_PHI(num)
  • num (int, required): Positive integer input.

Returns (int): Euler totient value of the input integer.

Example 1: primePy phi of one

Inputs:

num
1

Excel formula:

=PPY_PHI(1)

Expected output:

0

Example 2: primePy phi of prime integer

Inputs:

num
29

Excel formula:

=PPY_PHI(29)

Expected output:

28

Example 3: primePy phi of prime power

Inputs:

num
27

Excel formula:

=PPY_PHI(27)

Expected output:

18

Example 4: primePy phi of composite integer

Inputs:

num
60

Excel formula:

=PPY_PHI(60)

Expected output:

16

Python Code

Show Code
from primePy import primes as primepy_primes

def ppy_phi(num):
    """
    Compute Euler's totient function using the primePy implementation.

    See: https://github.com/janaindrajit/primePy

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

    Args:
        num (int): Positive integer input.

    Returns:
        int: Euler totient value of the input integer.
    """
    try:
        if isinstance(num, bool):
            return "Error: num must be an integer"

        num_value = int(num)
        if float(num) != float(num_value):
            return "Error: num must be an integer"
        if num_value <= 0:
            return "Error: num must be positive"

        return int(primepy_primes.phi(num_value))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Positive integer input.

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

Show 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.

PROPDIVS

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

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

D_{\text{proper}}(n) = \{d \in \mathbb{N} : d \mid n,\ d < n\}

The output is formatted as a 2D array so it can spill correctly in Excel.

Excel Usage

=PROPDIVS(n)
  • n (int, required): Integer whose proper divisors are listed.

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

Example 1: Proper divisors of twenty four

Inputs:

n
24

Excel formula:

=PROPDIVS(24)

Expected output:

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

Inputs:

n
13

Excel formula:

=PROPDIVS(13)

Expected output:

1

Example 3: Proper divisors of one

Inputs:

n
1

Excel formula:

=PROPDIVS(1)

Expected output:

""

Example 4: Proper divisors of a perfect square

Inputs:

n
36

Excel formula:

=PROPDIVS(36)

Expected output:

Result
1
2
3
4
6
9
12
18

Python Code

Show Code
from sympy import proper_divisors as sympy_proper_divisors

def propdivs(n):
    """
    List proper divisors of an integer.

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

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

    Args:
        n (int): Integer whose proper divisors are listed.

    Returns:
        list[list]: One-column 2D array of proper 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_proper_divisors(n_value, generator=False)
        if not values:
            return [[""]]
        return [[int(value)] for value in values]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Integer whose proper divisors are listed.

REDUCEDTOT

This function computes Carmichael’s reduced totient function \lambda(n), the smallest positive exponent that maps all units modulo n to 1.

\lambda(n) = \min\{m \in \mathbb{N} : a^m \equiv 1 \pmod{n}\ \text{for all } a\ \text{with } \gcd(a,n)=1\}

It is also known as the exponent of the multiplicative group modulo n and is used in modular arithmetic analysis.

Excel Usage

=REDUCEDTOT(n)
  • n (int, required): Positive integer input.

Returns (int): Carmichael reduced totient value of the input integer.

Example 1: Reduced totient of one

Inputs:

n
1

Excel formula:

=REDUCEDTOT(1)

Expected output:

1

Example 2: Reduced totient of power of two

Inputs:

n
16

Excel formula:

=REDUCEDTOT(16)

Expected output:

4

Example 3: Reduced totient of a composite integer

Inputs:

n
30

Excel formula:

=REDUCEDTOT(30)

Expected output:

4

Example 4: Reduced totient of odd composite integer

Inputs:

n
45

Excel formula:

=REDUCEDTOT(45)

Expected output:

12

Python Code

Show Code
from sympy import reduced_totient as sympy_reduced_totient

def reducedtot(n):
    """
    Compute Carmichael's reduced totient function for an integer.

    See: https://docs.sympy.org/latest/modules/functions/combinatorial.html#sympy.functions.combinatorial.numbers.reduced_totient

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

    Args:
        n (int): Positive integer input.

    Returns:
        int: Carmichael reduced totient value of the input integer.
    """
    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"
        if n_value <= 0:
            return "Error: n must be positive"

        return int(sympy_reduced_totient(n_value))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Positive integer input.

TOTIENT

This function computes Euler’s totient function, which counts how many positive integers up to n are coprime with n.

\varphi(n) = \#\{k \in \mathbb{N} : 1 \le k \le n,\ \gcd(k, n) = 1\}

The totient function is fundamental in modular arithmetic, multiplicative number theory, and public-key cryptography.

Excel Usage

=TOTIENT(n)
  • n (int, required): Positive integer input.

Returns (int): Euler totient value of the input integer.

Example 1: Totient of one

Inputs:

n
1

Excel formula:

=TOTIENT(1)

Expected output:

1

Example 2: Totient of a prime integer

Inputs:

n
29

Excel formula:

=TOTIENT(29)

Expected output:

28

Example 3: Totient of a prime power

Inputs:

n
27

Excel formula:

=TOTIENT(27)

Expected output:

18

Example 4: Totient of a composite integer

Inputs:

n
60

Excel formula:

=TOTIENT(60)

Expected output:

16

Python Code

Show Code
from sympy import totient as sympy_totient

def totient(n):
    """
    Compute Euler's totient function for an integer.

    See: https://docs.sympy.org/latest/modules/functions/combinatorial.html#sympy.functions.combinatorial.numbers.totient

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

    Args:
        n (int): Positive integer input.

    Returns:
        int: Euler totient value of the input integer.
    """
    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"
        if n_value <= 0:
            return "Error: n must be positive"

        return int(sympy_totient(n_value))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Positive integer input.