Back to Academy
math misc
Sieve of Eratosthenes
The Sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to a given limit. It works by iteratively marking the multiples of each prime starting from 2. The algorithm is highly efficient with O(n log log n) time complexity.
Use Cases
- •Generating prime numbers for cryptographic key generation
- •Solving number theory problems in competitive programming
- •Precomputing prime factorizations for batch queries
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(n log log n) | O(n log log n) | O(n log log n) |
| Space | O(n) | ||
Visualization
Implementation
Output
Click "Run Code" to see output...