Skip to content

Commit 4520f8f

Browse files
authored
Merge pull request thuva4#395 from pranjalrai/master
Added Extended Eulidean Algorithm in C++.
2 parents 62bb650 + 7187ea8 commit 4520f8f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
int d, x, y;
2+
3+
void Extended_Euclid(int A, int B) // a given equation of form Ax+By, extended euclid finds the gcd of A and B as well as the co-efficients of A and B
4+
{
5+
if(B == 0)
6+
{
7+
d = A;
8+
x = 1;
9+
y = 0;
10+
}
11+
else
12+
{
13+
Extended_Euclid(B, A%B);
14+
int temp = x;
15+
x = y;
16+
y = temp - (A/B)*y;
17+
}
18+
}
19+
20+
int main( )
21+
{
22+
int m,n;
23+
cin>>m>>n;
24+
extendedEuclid(m, n);
25+
cout << "The GCD of m and n is " << d << endl;
26+
cout << "Coefficient x and y are: "<< x << "and " << y << endl;
27+
return 0;
28+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Segmented Sieve |:+1:| :+1: | | | :+1: | | | |
6565
Union Find |:+1:|:+1:| | :+1: | | | | |
6666
Xor swap |:+1:|:+1:| | | |:+1:|:+1:| |
6767
Connected-component labeling | | | | |:+1:| | | |
68+
Extended Euclidean algorithm | | | | |:+1:| | | |
6869

6970

7071
### List of Algorithms :

0 commit comments

Comments
 (0)