We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ac3f94e commit 40726c6Copy full SHA for 40726c6
Other Basic/Euclids.cpp
@@ -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