PREVPRIME
This function finds the greatest prime that is strictly less than the given integer.
For an integer n, it returns a prime p such that p < n and there is no prime q with p < q < n.
This operation is useful when traversing prime values in descending order.
Excel Usage
=PREVPRIME(n)
n(int, required): Upper bound integer.
Returns (int): Largest prime number strictly less than n.
Example 1: Previous prime below ten
Inputs:
| n |
|---|
| 10 |
Excel formula:
=PREVPRIME(10)
Expected output:
7
Example 2: Previous prime below thirteen
Inputs:
| n |
|---|
| 13 |
Excel formula:
=PREVPRIME(13)
Expected output:
11
Example 3: Previous prime below one hundred
Inputs:
| n |
|---|
| 100 |
Excel formula:
=PREVPRIME(100)
Expected output:
97
Example 4: Previous prime below three
Inputs:
| n |
|---|
| 3 |
Excel formula:
=PREVPRIME(3)
Expected output:
2
Python Code
from sympy import prevprime as sympy_prevprime
def prevprime(n):
"""
Return the largest prime smaller than a given 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): Upper bound integer.
Returns:
int: Largest prime number strictly less than n.
"""
try:
result = sympy_prevprime(n)
return int(result)
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Upper bound integer.