Sign in Join
Wiki copytemporary

Greatest common divisor/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Greatest common divisor/fr

OldNewLine
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+
3+Il existe plusieurs méthodes pour le calculer. P.ex., l'algorithme d'Euclide basé sur la division peut être implémenté.
4+
5+## Fonction GreatestCommonDivisor
6+
7+``` pascal
8+
9+function GreatestCommonDivisor(a, b: Int64): Int64;
10+var
11+ temp: Int64;
12+begin
13+ while b <> 0 do
14+ begin
15+ temp := b;
16+ b := a mod b;
17+ a := temp
18+ end;
19+ result := a
20+end;
21+
22+function GreatestCommonDivisor_EuclidsSubtractionMethod(a, b: Int64): Int64;
23+//only works with positive integers
24+begin
25+ if (a < 0) then a := -a;
26+ if (b < 0) then b := -b;
27+ if (a = 0) then Exit(b);
28+ if (b = 0) then Exit(a);
29+ while not (a = b) do
30+ begin
31+ if (a > b) then
32+ a := a - b
33+ else
34+ b := b - a;
35+ end;
36+ Result := a;
37+end;
38+```
39+
40+## Voir aussi
41+
42+- [Recursive example](http://rosettacode.org/wiki/Greatest_common_divisor#Pascal_.2F_Delphi_.2F_Free_Pascal)
43+- [[Least common multiple/fr|plus petit multiple commun]]
44+- [[Mod/fr|Mod]]
45+
46+---
47+*From the Free Pascal wiki, page "Greatest common divisor/fr", as it stood on 2020-02-16 after a change by Trev, out of the wiki's dump of 2024-05-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).*

Back to history