PRIME

This function returns the prime at a given 1-based index in the ordered prime sequence.

If p_n denotes the nth prime, the function computes p_n where p_1 = 2, p_2 = 3, and so on.

This supports direct lookup of prime values by position.

Excel Usage

=PRIME(nth)
  • nth (int, required): One-based index of the desired prime number.

Returns (int): The nth prime number.

Example 1: First prime index

Inputs:

nth
1

Excel formula:

=PRIME(1)

Expected output:

2

Example 2: Tenth prime index

Inputs:

nth
10

Excel formula:

=PRIME(10)

Expected output:

29

Example 3: Fiftieth prime index

Inputs:

nth
50

Excel formula:

=PRIME(50)

Expected output:

229

Example 4: Hundredth prime index

Inputs:

nth
100

Excel formula:

=PRIME(100)

Expected output:

541

Python Code

from sympy import prime as sympy_prime

def prime(nth):
    """
    Return the nth prime number.

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

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

    Args:
        nth (int): One-based index of the desired prime number.

    Returns:
        int: The nth prime number.
    """
    try:
        result = sympy_prime(nth)
        return int(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

One-based index of the desired prime number.