Skip to content

Commit 87c5581

Browse files
committed
README file added for GCD
1 parent 9e5af7e commit 87c5581

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Number Theory/GCD/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Greatest Commond Divisor Finding (Euclidean algorithm)
2+
3+
The **Greatest Common Divisor (GCD)** of two integers A and B is the *largest integer that divides both A and B*. For example, the gcd of 8 and 12 is 4.
4+
5+
The greatest common divisor is also known as the greatest common factor (gcf), highest common factor (hcf), greatest common measure (gcm), or highest common divisor.
6+
7+
**Euclid's algorithm**, is an efficient method for computing the greatest common divisor (GCD) of two numbers, the largest number that divides both of them without leaving a remainder.
8+
9+
#### Using Euclid's algorithm:
10+
11+
Euclidean algorithm, uses a division algorithm such as long division in combination with the observation that the gcd of two numbers also divides their difference. To compute gcd(48,18), divide 48 by 18 to get a quotient of 2 and a remainder of 12. Then divide 18 by 12 to get a quotient of 1 and a remainder of 6. Then divide 12 by 6 to get a remainder of 0, which means that 6 is the gcd. Note that we ignored the quotient in each step except to notice when the remainder reached 0, signaling that we had arrived at the answer. Formally the algorithm can be described as:
12+
13+
```
14+
gcd(a,0) = a
15+
gcd(a,b) = gcd(b, a mod b)
16+
```
17+
18+
where
19+
20+
```
21+
a mod b = a - b * floor(a/b)
22+
```
23+
24+
If the arguments are both greater than zero then the algorithm can be written in more elementary terms as follows:
25+
26+
```
27+
gcd(a,a) = a
28+
gcd(a,b) = gcd(a-b, b), if a > b
29+
gcd(a,b) = gcd(a, b-a), if b > a
30+
```
31+
32+
### More on this topic
33+
- [Euclidean algorithm - Wikipedia](https://en.wikipedia.org/wiki/Euclidean_algorithm)
34+
- [GCD - Wikipedia](https://en.wikipedia.org/wiki/Greatest_common_divisor)
35+
- [Euclidean algorithm - khanacademy](https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595

9696
- Number Theory
97-
- Greatest Common Divisor (GCD)
97+
- [Greatest Common Divisor (GCD)](./Number%20Theory/GCD/)
9898
- Longest Common Multiplier (LCM)
9999
- Euler Totient (Phi)
100100
- Primality Testing

0 commit comments

Comments
 (0)