🔢 Generate Prime Numbers

Generate prime numbers using the Sieve of Eratosthenes algorithm:

Find all primes ≤ n or first k primes
Uses efficient sieve algorithm for large ranges
Choose how to generate the prime numbers
Find all primes up to this number (max 1,000,000)

🔢 Understanding Prime Numbers

Prime numbers are integers greater than 1 that have no positive divisors other than 1 and themselves. They are the building blocks of number theory and have fascinated mathematicians for centuries.

🧮 What is a Prime Number?

📐 Definition

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples: 2, 3, 5, 7, 11, 13, 17, 19, 23...

⚡ Composite Numbers

Numbers greater than 1 that are not prime. They can be factored into smaller integers. Examples: 4, 6, 8, 9, 10, 12, 14, 15, 16...

🎯 Special Case: 2

2 is the only even prime number. All other even numbers are composite because they are divisible by 2.

🔢 Special Case: 1

1 is neither prime nor composite. It has only one positive divisor (itself) and doesn't fit the definition of prime numbers.

⚙️ Sieve of Eratosthenes

📜 Ancient Algorithm

Invented by Greek mathematician Eratosthenes around 200 BC. Still one of the most efficient ways to find all primes up to a limit.

🔄 How It Works

1. Create list of numbers from 2 to n
2. Start with smallest number (2)
3. Mark all multiples as composite
4. Move to next unmarked number
5. Repeat until √n

⚡ Efficiency

Time complexity: O(n log log n)
Space complexity: O(n)
Very efficient for finding all primes up to n
Optimal for ranges up to ~10^7

💻 Implementation

Uses boolean array for marking
Crosses out multiples of each prime
Collects remaining unmarked numbers
Perfect for this calculator

🧮 Prime Number Properties

♾️ Infinite Count

Euclid proved there are infinitely many primes around 300 BC. This was one of the first proofs by contradiction in mathematics.

📊 Distribution

Prime numbers become less frequent as numbers get larger. The Prime Number Theorem describes this distribution pattern.

👯 Twin Primes

Pairs of primes differing by 2 (e.g., 11-13, 17-19, 29-31). It's conjectured there are infinitely many twin primes.

🔐 Cryptography

RSA encryption relies on the difficulty of factoring large composite numbers into their prime factors.

💡 Prime Number Fact: The largest known prime number has over 24 million digits and was discovered by the Great Internet Mersenne Prime Search (GIMPS) project. It's a Mersenne prime of the form 2^82,589,933 - 1.

🔬 Famous Prime Numbers

2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

🎯 Applications of Prime Numbers

🔐 Cybersecurity

RSA encryption algorithm
Public-key cryptography
Digital signatures
Secure communications

💻 Computer Science

Hash table sizing
Pseudorandom number generation
Computer graphics
Algorithm optimization

📊 Statistics

Random sampling methods
Monte Carlo simulations
Quality control
Experimental design

🎵 Music Theory

Harmonic series
Just intonation
Frequency ratios
Scale construction

🧪 Testing Primality

🔍 Trial Division

Divide by all numbers up to √n
Simple but slow for large numbers
O(√n) time complexity
Works well for small n

🎯 Fermat's Test

Probabilistic primality test
Fermat's Little Theorem
Fast but not always accurate
Used in some applications

🧬 Miller-Rabin Test

Deterministic for small numbers
Very fast and reliable
Used in cryptographic applications
Modern standard method

🔢 AKS Primality Test

Deterministic and polynomial-time
Mathematically proven correct
Too slow for practical use
Theoretical breakthrough

🌟 Unsolved Problems

👯 Twin Prime Conjecture

Are there infinitely many twin primes?
One of the most famous unsolved problems
Related to the distribution of primes
Millennium Prize Problem

🎲 Goldbach Conjecture

Can every even number > 2 be written as sum of two primes?
Conjectured by Christian Goldbach in 1742
Verified up to very large numbers
Still unproven

📊 Riemann Hypothesis

Concerns the zeros of the Riemann zeta function
One of the seven Millennium Prize Problems
Implies bounds on prime gaps
Extremely important in number theory

🔄 Prime Gap Conjecture

How large can gaps between consecutive primes be?
Related to the distribution of primes
Recent breakthroughs by Zhang and Maynard
Still active area of research