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

external_packages = ['primePy==1.3']

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.