PRIMEPI

This function evaluates the prime-counting function \pi(n), which gives how many prime numbers are less than or equal to n.

Formally:

\pi(n) = \left|\{p \le n : p \text{ is prime}\}\right|

It is useful for density and distribution analysis of prime numbers.

Excel Usage

=PRIMEPI(n)
  • n (int, required): Inclusive upper limit for counting primes.

Returns (int): Number of primes less than or equal to n.

Example 1: Prime count up to ten

Inputs:

n
10

Excel formula:

=PRIMEPI(10)

Expected output:

4

Example 2: Prime count up to twenty five

Inputs:

n
25

Excel formula:

=PRIMEPI(25)

Expected output:

9

Example 3: Prime count up to one hundred

Inputs:

n
100

Excel formula:

=PRIMEPI(100)

Expected output:

25

Example 4: Prime count up to one

Inputs:

n
1

Excel formula:

=PRIMEPI(1)

Expected output:

0

Python Code

from sympy import primepi as sympy_primepi

def primepi(n):
    """
    Count the number of primes less than or equal to an integer.

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

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

    Args:
        n (int): Inclusive upper limit for counting primes.

    Returns:
        int: Number of primes less than or equal to n.
    """
    try:
        result = sympy_primepi(n)
        return int(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Inclusive upper limit for counting primes.