Skip to content

Commit 03a181a

Browse files
Create sieveoferatosthenes.cpp
create code/file for algorithm sieve of Eratosthenes
1 parent 2d7a8ec commit 03a181a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

others/sieveoferatosthenes.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
void sieveoferatosthenes(vector<ll>a,ll x){
2+
bool prime(x+1,true);
3+
4+
for(ll i=2;i*i<=x;i++){
5+
if(prime[i]==true){
6+
for(ll j=i*i;j<=x;j+=i){
7+
prime[i]=false;
8+
}
9+
}
10+
}
11+
for(ll i=2;i<=x;i++){
12+
if(prime[i])a.push_back(i);
13+
}
14+
}

0 commit comments

Comments
 (0)