๐Ÿ”ข 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