Prime Number Checker
Check if a number is prime and find all prime numbers up to a limit.
About this tool
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Prime numbers form the foundation of mathematics and cryptography, making them essential to modern security systems, number theory research, and computational algorithms. This tool helps you quickly verify whether a given number is prime and discover all prime numbers within a specified range.
To use the Prime Number Checker, simply enter a number in the first field to test if it's prime, and optionally specify an upper limit in the second field to generate all primes up to that value. The tool instantly displays the result along with a complete list of primes if you requested a range. This is particularly useful for students learning number theory, developers implementing cryptographic algorithms, and mathematicians exploring prime distribution patterns.
Frequently Asked Questions
Code Implementation
def is_prime(n: int) -> bool:
"""Check if n is a prime number."""
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def primes_up_to(limit: int) -> list[int]:
"""Sieve of Eratosthenes: find all primes up to limit."""
if limit < 2:
return []
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for i in range(2, int(limit**0.5) + 1):
if sieve[i]:
for j in range(i*i, limit + 1, i):
sieve[j] = False
return [i for i, v in enumerate(sieve) if v]
print(is_prime(17)) # True
print(is_prime(18)) # False
print(primes_up_to(50)) # [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.