All tools

Next & Previous Prime

Find the closest primes around any number.

100
is not prime
Previous prime
97
Next prime
101

Trial division up to √n. Fast enough for any number under about a billion. Beyond that you'd want Miller-Rabin or AKS. 1 is not prime by modern convention. The first ten primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29.

About

Enter any positive integer. The tool tells you whether it's prime and shows the next prime above and the previous prime below. Useful for finding hash table sizes, generating PRNG seeds, or settling math homework.

How to use

  1. Enter a number.
  2. Read primality and neighbors.

FAQ

How big can the input be?+

About a billion. The tool uses trial division up to √n, which is fast enough for that range. Beyond that you'd want a probabilistic test (Miller-Rabin).