Skip to content

Commit f95dc92

Browse files
author
Oleksandr Kulkov
authored
Update euclid-algorithm.md
articles + typos fix
1 parent 499dfb9 commit f95dc92

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/algebra/euclid-algorithm.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ The algorithm was first described in Euclid's "Elements" (circa 300 BC), but it
1414

1515
## Algorithm
1616

17-
Originally, Euclidean algorithm was formulated as follows: subtract smaller number from the larger one until one of the numbers is zero. Indeed, if $g$ divides $a$ and $b$, it also divides $a-b$. On the other hand, if $g$ divides $a-b$ and $b$, then it also divides $a = b + (a-b)$, which means that the sets of common divisors of $\{a, b\}$ and $\{b,a-b\}$ coincide.
17+
Originally, the Euclidean algorithm was formulated as follows: subtract the smaller number from the larger one until one of the numbers is zero. Indeed, if $g$ divides $a$ and $b$, it also divides $a-b$. On the other hand, if $g$ divides $a-b$ and $b$, then it also divides $a = b + (a-b)$, which means that the sets of the common divisors of $\{a, b\}$ and $\{b,a-b\}$ coincide.
1818

19-
Note that $a$ remains the larger number until $b$ is subtracted from it at least $\left\lfloor\frac{a}{b}\right\rfloor$ times. Therefore, to speed things up, $a-b$ is substituted with $a-\left\lfloor\frac{a}{b}\right\rfloor b = a \bmod b$. Then the algorithm can be formulated in an extremely simple way:
19+
Note that $a$ remains the larger number until $b$ is subtracted from it at least $\left\lfloor\frac{a}{b}\right\rfloor$ times. Therefore, to speed things up, $a-b$ is substituted with $a-\left\lfloor\frac{a}{b}\right\rfloor b = a \bmod b$. Then the algorithm is formulated in an extremely simple way:
2020

2121
$$\gcd(a, b) = \begin{cases}a,&\text{if }b = 0 \\\\ \gcd(b, a \bmod b),&\text{otherwise.}\end{cases}$$
2222

@@ -51,7 +51,7 @@ int gcd (int a, int b) {
5151
}
5252
```
5353
54-
Note that since C++17, `gcd` is implement as a [standard function](https://en.cppreference.com/w/cpp/numeric/gcd) in C++.
54+
Note that since C++17, `gcd` is implemented as a [standard function](https://en.cppreference.com/w/cpp/numeric/gcd) in C++.
5555
5656
## Time Complexity
5757

0 commit comments

Comments
 (0)