When dividing any positive integer by a positive integer , the result will be an integer if and only if is a divisor of . If is a prime number, its only divisors are and itself. To determine whether a number is prime, it suffices to check whether the division results in an integer for divisors from up to the greatest integer less than or equal to the square root of . For prime , none of the divisions by yields an integer. If we multiply the fractional parts of all these divisions, the result will be zero only when at least one of the factors is zero, that is, when the number is composite. Therefore, the function below, for , is zero only for composite numbers, and otherwise:
For from to , the empty product is equal to . Since is not prime, we can multiply the value by
which is zero only for . Thus, the function below, defined for positive integers, returns for any prime , and otherwise:
The function counts how many prime numbers exist from to , using the function defined above:
The value of is defined as zero, corresponding to the empty sum.
Let us define a function that equals when , and otherwise:
When , the denominator is greater than , and the entire expression evaluates to zero. Otherwise, it equals . Thus, equals only when , for a fixed .
If we have an upper bound for the -th prime, we can construct a function that returns the -th prime by summing the candidates that may be the -th prime, multiplied by a function that selects only the first such that .
When the index satisfies and , we have found exactly the -th prime.
Since grows approximately as , we can use upper bounds such as:
The first is based on the fact that is less than for , with smaller cases verifiable directly. The last grows very rapidly and serves as a guarantee when one does not have a good estimate of the value of the prime .
Obviously, the formula is not efficient. It is merely a mathematical notation for the primality testing algorithm that uses successive divisions up to the square root of the number being tested.
This formula was created (discovered?) on 2026-05-04 by José Eduardo Gaboardi de Carvalho (edu.a1978 at gmail).