-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhcforgcd.cpp
More file actions
89 lines (74 loc) · 1.38 KB
/
Copy pathhcforgcd.cpp
File metadata and controls
89 lines (74 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<bits/stdc++.h>
using namespace std;
//EUCLID OPTIMIZED
int gcd(int a,int b)
{
if (b ==0)
return a;
else
b = gcd(b,a%b);
}
int main()
{
int x = 100 ,y =200;
gcd(x,y);
cout<<gcd(x,y);
return 0;
}
//EUCLID METHOD
// int gcd(int a, int b)
// {
// while (a!=b)
// {
// if (a>b)
// {
// a = a - b;
// }
// else
// {
// b = b-a;
// }
// }
// return a;
// }
// int main()
// {
// int x = 22,y = 11;
// gcd(x,y);
// cout<<gcd(x,y);
// return 0;
// }
//GCD NAIVE METHOD WITH COMPLEXITY O(MIN(X,Y))
// int gcd(int x,int y)
// {
// int res = min(x,y);
// while (res > 0)
// {
// if(x % res == 0 && y % res == 0)
// {
// break;
// }
// res--;
// }
// return res;
// }
// int main()
// {
// int a =10,b=15;
// gcd(a,b);
// cout<<gcd(a,b);
// return 0;
// }
//GCD NAIVE METHOD
// int n1,n2,i,gcd;
// cout<<"Enter two integers :"<<endl;
// cin>>n1>>n2;
// for(i=1;i<=n1&& i<=n2;i++)
// {
// if(n1%i==0 && n2%i==0)
// {
// gcd=i;
// }
// }
// cout<<"GCD of "<<n1<<" and "<<n2<<" is "<< gcd;
// }