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

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.