Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cpp/a.out
Binary file not shown.
7 changes: 4 additions & 3 deletions cpp/sieve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ void SieveOfEratosthenes(int n)
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
bool prime[n + 1];
vector<bool> prime(n + 1, 1);
prime[0]=prime[1]=0;

for(int p = 2; p*p <= n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == true)
{
// Update all multiples of p
for(int i = p*2; i <= n; i += p)
for(int i = p*p; i <= n; i += p)
prime[i] = false;
}
}
Expand All @@ -39,4 +40,4 @@ int main()
Output :- ( For n = 20 )
Following are the prime numbers smaller than or equal to 20
2 3 5 7 11 13 17 19
*/
*/