https://github.com/shaldonbarnes10/sieve_of_eratostenes_algorithm
Sieve of Eratostenes implementation using c++
https://github.com/shaldonbarnes10/sieve_of_eratostenes_algorithm
algorithms-and-data-structures sieve-of-eratosthenes
Last synced: 25 days ago
JSON representation
Sieve of Eratostenes implementation using c++
- Host: GitHub
- URL: https://github.com/shaldonbarnes10/sieve_of_eratostenes_algorithm
- Owner: Shaldonbarnes10
- Created: 2025-01-12T17:34:01.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-01-12T17:45:38.000Z (4 months ago)
- Last Synced: 2025-02-14T13:41:56.366Z (3 months ago)
- Topics: algorithms-and-data-structures, sieve-of-eratosthenes
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sieve of Eratosthenes
This project implements the **Sieve of Eratosthenes**, an efficient algorithm to find all prime numbers up to a given number `n`. The algorithm uses a boolean array to mark multiples of each prime as non-prime, resulting in a list of prime numbers.
---
## Features
- Input a number `n` and find all prime numbers up to `n`.
- Efficient implementation with a time complexity of \(O(n \log \log n)\).
- Handles large input values efficiently.---
## How It Works
1. **Initialization**:
Create a boolean array (`primes[]`) of size \(n+1\) and initialize all elements to `true`.
Set `primes[0]` and `primes[1]` to `false` as 0 and 1 are not prime.2. **Mark Non-Primes**:
Starting from \(p = 2\), mark all multiples of \(p\) (from \(p^2\) to \(n\)) as `false`.3. **Output Primes**:
Print all indices of the array still marked as `true`.---