Greatest common divisor/fr: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 1 | + | Le plus grand diviseur commun (PGDC) de deux entiers est le plus grand entier qui les divise les deux. Si les nombres sont 121 et 143 alors le PGDC est 11 (121=11x11 et 143=11*13) | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | Il existe plusieurs méthodes pour le calculer. P.ex., l'algorithme d'Euclide basé sur la division peut être implémenté. | |
| 4 | 4 | ||
| 5 | 5 | ## Fonction GreatestCommonDivisor | |
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 6 | + | ``` | |
| 9 | 7 | function GreatestCommonDivisor(a, b: Int64): Int64; | |
| 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 | - | ||
| 8 | + | var | |
| 9 | + | temp: Int64; | |
| 10 | + | begin | |
| 11 | + | while b <> 0 do | |
| 12 | + | begin | |
| 13 | + | temp := b; | |
| 14 | + | b := a mod b; | |
| 15 | + | a := temp | |
| 16 | + | end; | |
| 17 | + | result := a | |
| 18 | + | end; | |
| 19 | + | ||
| 20 | + | function GreatestCommonDivisor_EuclidsSubtractionMethod(a, b: Int64): Int64; | |
| 21 | + | //only works with positive integers | |
| 22 | + | begin | |
| 23 | + | if (a < 0) then a := -a; | |
| 24 | + | if (b < 0) then b := -b; | |
| 25 | + | if (a = 0) then Exit(b); | |
| 26 | + | if (b = 0) then Exit(a); | |
| 27 | + | while not (a = b) do | |
| 28 | + | begin | |
| 29 | + | if (a > b) then | |
| 30 | + | a := a - b | |
| 31 | + | else | |
| 32 | + | b := b - a; | |
| 33 | + | end; | |
| 34 | + | Result := a; | |
| 35 | + | end; | |
| 38 | 36 | ``` | |
| 39 | 37 | ||
| 40 | 38 | ## Voir aussi | |
| 41 | 39 | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 40 | + | * [Recursive example](<http://rosettacode.org/wiki/Greatest_common_divisor#Pascal_.2F_Delphi_.2F_Free_Pascal>) | |
| 41 | + | * [[Least common multiple/fr|plus petit multiple commun]] | |
| 42 | + | * [[Mod/fr|Mod]] | |
| 45 | 43 | ||
| 46 | 44 | --- | |
| 47 | - | ||
| 45 | + | *From the Free Pascal wiki, page "Greatest common divisor/fr", as the Internet Archive kept it on 2023-03-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
