What is the 1000th prime number? The millionth? The Nth Prime API finds any prime number by its position in the infinite sequence of primes, instantly returning results for positions up to several million.
What are Prime Numbers?
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29...
Prime numbers are fundamental to number theory and have crucial applications in cryptography, where large primes are used in encryption algorithms.
The Prime Number Sequence
Notable primes in the sequence:
| Position (n) | Prime Number |
|---|---|
| 1 | 2 |
| 10 | 29 |
| 100 | 541 |
| 1,000 | 7,919 |
| 10,000 | 104,729 |
| 100,000 | 1,299,709 |
| 1,000,000 | 15,485,863 |
Using the Nth Prime API
TinyFn provides a fast endpoint to find any prime by position:
GET https://api.tinyfn.io/v1/math/nth-prime?n=1000
Headers: X-API-Key: your-api-key
{
"n": 1000,
"prime": 7919,
"previous_prime": 7907,
"next_prime": 7927,
"digit_count": 4
}
Parameters
| Parameter | Type | Description |
|---|---|---|
n |
integer | Position in prime sequence (required, 1 to 10,000,000) |
include_neighbors |
boolean | Include previous and next primes (default: true) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/math/nth-prime?n=10000',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(`The 10,000th prime is ${data.prime}`); // 104729
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/math/nth-prime',
headers={'X-API-Key': 'your-api-key'},
params={'n': 1000000}
)
data = response.json()
print(f"The millionth prime is: {data['prime']:,}") # 15,485,863
cURL
curl "https://api.tinyfn.io/v1/math/nth-prime?n=100" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Cryptography: Generate prime numbers for encryption keys
- Educational Tools: Teach about prime numbers and sequences
- Math Challenges: Project Euler and similar programming puzzles
- Random Prime Selection: Pick primes at specific positions
- Prime Verification: Check position of known primes
Best Practices
- Cache frequent results: Common positions like 100, 1000 are often requested
- Use batching: Request ranges with the primes-in-range endpoint when needed
- Consider approximations: For very large n, prime estimates may suffice
- Handle limits: Very large positions may exceed API limits
- Verify for cryptography: For security-critical primes, use additional verification