|
6522 | 6522 |
|
6523 | 6523 |
|
6524 | 6524 |
|
| 6525 | + |
| 6526 | + |
| 6527 | + |
| 6528 | + |
| 6529 | + |
| 6530 | + |
| 6531 | + |
| 6532 | + |
6525 | 6533 |
|
6526 | 6534 |
|
6527 | 6535 |
|
|
6620 | 6628 |
|
6621 | 6629 |
|
6622 | 6630 |
|
| 6631 | + |
| 6632 | + |
| 6633 | + |
| 6634 | + |
6623 | 6635 |
|
6624 | 6636 |
|
6625 | 6637 |
|
|
6632 | 6644 | <ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
|
6633 | 6645 |
|
6634 | 6646 | Last update:
|
6635 |
| - <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">July 11, 2024</span>  |
| 6647 | + <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">October 13, 2024</span>  |
6636 | 6648 |
|
6637 | 6649 | <!-- Tags -->
|
6638 | 6650 |
|
@@ -6664,7 +6676,7 @@ <h1 id="euclidean-algorithm-for-computing-the-greatest-common-divisor">Euclidean
|
6664 | 6676 | <div class="arithmatex">$$\gcd(a, b) = \max \{k > 0 : (k \mid a) \text{ and } (k \mid b) \}$$</div>
|
6665 | 6677 | <p>(here the symbol "<span class="arithmatex">$\mid$</span>" denotes divisibility, i.e. "<span class="arithmatex">$k \mid a$</span>" means "<span class="arithmatex">$k$</span> divides <span class="arithmatex">$a$</span>")</p>
|
6666 | 6678 | <p>When one of the numbers is zero, while the other is non-zero, their greatest common divisor, by definition, is the second number. When both numbers are zero, their greatest common divisor is undefined (it can be any arbitrarily large number), but it is convenient to define it as zero as well to preserve the associativity of <span class="arithmatex">$\gcd$</span>. Which gives us a simple rule: if one of the numbers is zero, the greatest common divisor is the other number.</p>
|
6667 |
| -<p>The Euclidean algorithm, discussed below, allows to find the greatest common divisor of two numbers <span class="arithmatex">$a$</span> and <span class="arithmatex">$b$</span> in <span class="arithmatex">$O(\log \min(a, b))$</span>.</p> |
| 6679 | +<p>The Euclidean algorithm, discussed below, allows to find the greatest common divisor of two numbers <span class="arithmatex">$a$</span> and <span class="arithmatex">$b$</span> in <span class="arithmatex">$O(\log \min(a, b))$</span>. Since the function is <strong>associative</strong>, to find the GCD of <strong>more than two numbers</strong>, we can do <span class="arithmatex">$\gcd(a, b, c) = \gcd(a, \gcd(b, c))$</span> and so forth.</p> |
6668 | 6680 | <p>The algorithm was first described in Euclid's "Elements" (circa 300 BC), but it is possible that the algorithm has even earlier origins.</p>
|
6669 | 6681 | <h2 id="algorithm">Algorithm<a class="headerlink" href="#algorithm" title="Permanent link">¶</a></h2>
|
6670 | 6682 | <p>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 <span class="arithmatex">$g$</span> divides <span class="arithmatex">$a$</span> and <span class="arithmatex">$b$</span>, it also divides <span class="arithmatex">$a-b$</span>. On the other hand, if <span class="arithmatex">$g$</span> divides <span class="arithmatex">$a-b$</span> and <span class="arithmatex">$b$</span>, then it also divides <span class="arithmatex">$a = b + (a-b)$</span>, which means that the sets of the common divisors of <span class="arithmatex">$\{a, b\}$</span> and <span class="arithmatex">$\{b,a-b\}$</span> coincide.</p>
|
@@ -6744,7 +6756,7 @@ <h2 id="practice-problems">Practice Problems<a class="headerlink" href="#practic
|
6744 | 6756 |
|
6745 | 6757 | <ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
|
6746 | 6758 | <span class="contributors-text">Contributors:</span>
|
6747 |
| - <ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/jakobkogler" title="jakobkogler" data-bi-name="contributorprofile" target="_blank">jakobkogler</a> (48.06%)</li><li><a href="#" title="Nalin Bhardwaj" data-bi-name="contributorprofile" target="_blank">Nalin Bhardwaj</a> (34.11%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (11.63%)</li><li><a href="https://github.com/tcNickolas" title="tcNickolas" data-bi-name="contributorprofile" target="_blank">tcNickolas</a> (3.88%)</li><li><a href="https://github.com/AniketR10" title="AniketR10" data-bi-name="contributorprofile" target="_blank">AniketR10</a> (0.78%)</li><li><a href="https://github.com/itssachinkr" title="itssachinkr" data-bi-name="contributorprofile" target="_blank">itssachinkr</a> (0.78%)</li><li><a href="https://github.com/jinyulink" title="jinyulink" data-bi-name="contributorprofile" target="_blank">jinyulink</a> (0.78%)</li></ul> |
| 6759 | + <ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/jakobkogler" title="jakobkogler" data-bi-name="contributorprofile" target="_blank">jakobkogler</a> (47.29%)</li><li><a href="#" title="Nalin Bhardwaj" data-bi-name="contributorprofile" target="_blank">Nalin Bhardwaj</a> (34.11%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (11.63%)</li><li><a href="https://github.com/tcNickolas" title="tcNickolas" data-bi-name="contributorprofile" target="_blank">tcNickolas</a> (3.88%)</li><li><a href="https://github.com/mdeapedro" title="mdeapedro" data-bi-name="contributorprofile" target="_blank">mdeapedro</a> (0.78%)</li><li><a href="https://github.com/AniketR10" title="AniketR10" data-bi-name="contributorprofile" target="_blank">AniketR10</a> (0.78%)</li><li><a href="https://github.com/itssachinkr" title="itssachinkr" data-bi-name="contributorprofile" target="_blank">itssachinkr</a> (0.78%)</li><li><a href="https://github.com/jinyulink" title="jinyulink" data-bi-name="contributorprofile" target="_blank">jinyulink</a> (0.78%)</li></ul> |
6748 | 6760 | </ul>
|
6749 | 6761 |
|
6750 | 6762 | </article>
|
|
0 commit comments