Skip to content

Commit 40726c6

Browse files
Day 21 Euclid and Seive of Erastothenes
1 parent ac3f94e commit 40726c6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Other Basic/Euclids.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
// Euclids Algo
6+
int gcd(int a,int b){
7+
if(b==0) return a;
8+
9+
return gcd(b,a%b);
10+
}
11+
12+
// Seive Of Erastothenes
13+
14+
vector<bool> seiveOfErastothenes(int n){
15+
vector<bool> isprime(n+1,true);
16+
// memset(isprime,sizeof(isprime),true);
17+
isprime[0]=false;
18+
isprime[1]=false;
19+
20+
for(int i=2;i*i<=n;i++){
21+
for(int j=2*i;j<=n;j+=i){
22+
isprime[j]=false;
23+
}
24+
}
25+
return isprime;
26+
}
27+
28+
int main(){
29+
int n=20;
30+
vector<bool> isprime=seiveOfErastothenes(n);
31+
for(int i=1;i<=n;i++){
32+
cout << i << " " << isprime[i] << endl;
33+
}
34+
35+
int a=24,b=60;
36+
cout << "GCD of 24 and 60 is " << gcd(24,60) << endl;
37+
return 0;
38+
}

0 commit comments

Comments
 (0)