Sign in Join
Wiki copytemporary

Greatest common divisor/pl: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Największy wspólny dzielnik
22
3-The greatest common divisor of two integers is the largest integer that divides them both. If numbers are 121 and 143 then greatest common divisor is 11.
4-
5-There are many methods to calculate this. For example, the division-based Euclidean algorithm version may be programmed:
6-
7-Największym wspólnym dzielnikiem dwóch liczb całkowitych jest największa liczba całkowita, która dzieli je obie bez reszty. Jeśli liczby wynoszą 121 i 143, to największy wspólny dla nich dzielnik wynosi 11.
3+Największym wspólnym dzielnikiem dwóch liczb całkowitych jest największa liczba całkowita, która dzieli je obie bez reszty. Jeśli liczby wynoszą 121 i 143, to największy wspólny dla nich dzielnik wynosi 11.
84
9-Istnieje wiele metod obliczania największego wspólnego dzielnika dwóch liczb. Można na przykład zaprogramować wersję algorytmu Euklidesa opartego na dzieleniu:
5+Istnieje wiele metod obliczania największego wspólnego dzielnika dwóch liczb. Można na przykład zaprogramować wersję algorytmu Euklidesa opartego na dzieleniu:
106
117## `function greatestCommonDivisor`
12-
13-``` pascal
8+```
149function greatestCommonDivisor(a, b: Int64): Int64;
15-var
16- temp: Int64;
17-begin
18- while b <> 0 do
19- begin
20- temp := b;
21- b := a mod b;
22- a := temp
23- end;
24- result := a
25-end;
26-
27-function greatestCommonDivisor_euclidsSubtractionMethod(a, b: Int64): Int64;
28-begin
29- // działa tylko z dodatnimi liczbami całkowitymi
30- if (a < 0) then a := -a;
31- if (b < 0) then b := -b;
32- // nie wchodź do pętli warunkowej, ponieważ odjęcie zera sprawi, że nie będzie mogła zostać przerwana
33- if (a = 0) then exit(b);
34- if (b = 0) then exit(a);
35- while not (a = b) do
36- begin
37- if (a > b) then
38- a := a - b
39- else
40- b := b - a;
41- end;
42- result := a;
43-end;
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+ begin
24+ // działa tylko z dodatnimi liczbami całkowitymi
25+ if (a < 0) then a := -a;
26+ if (b < 0) then b := -b;
27+ // nie wchodź do pętli warunkowej, ponieważ odjęcie zera sprawi, że nie będzie mogła zostać przerwana
28+ if (a = 0) then exit(b);
29+ if (b = 0) then exit(a);
30+ while not (a = b) do
31+ begin
32+ if (a > b) then
33+ a := a - b
34+ else
35+ b := b - a;
36+ end;
37+ result := a;
38+ end;
4439```
4540
4641## Zobacz także
4742
48-- [[Least common multiple|Najmniejsza wspólna wielokrotność]]
49-- [[Mod|Operator mod]]
50-- `mpz_gcd` in [[gmp|GMP]] (GNU multiple precision)
43+ * [[Least common multiple|Najmniejsza wspólna wielokrotność]]
44+ * [[Mod|Operator `mod`]]
45+ * `mpz_gcd` in [[gmp|GMP]] (GNU multiple precision)
5146
5247## zewnętrzne odnośniki
5348
54-- [Przykład rekurencyjny](https://rosettacode.org/wiki/Greatest_common_divisor#Pascal_.2F_Delphi_.2F_Free_Pascal)
49+ * [Przykład rekurencyjny](<https://rosettacode.org/wiki/Greatest_common_divisor#Pascal_.2F_Delphi_.2F_Free_Pascal>)
5550
5651---
57-*From the Free Pascal wiki, page "Greatest common divisor/pl", as it stood on 2023-10-07 after a change by Slawek, 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).*
58-Category: Mathematics
52+*From the Free Pascal wiki, page "Greatest common divisor/pl", as the Internet Archive kept it on 2025-02-08, last changed on 2024-07-28. 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