Sign in Join
Wiki copytemporary

Greatest common divisor/pl: what changed

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

OldNewLine
1-<div style="font-size:1.88em;margin:0.75em 0;">
2-
31Największy wspólny dzielnik
4-
5-</div>
62
73The 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.
84
95There are many methods to calculate this. For example, the division-based Euclidean algorithm version may be programmed:
106
117Najwię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.
128
139Istnieje wiele metod obliczania największego wspólnego dzielnika dwóch liczb. Można na przykład zaprogramować wersję algorytmu Euklidesa opartego na dzieleniu:
1410
1511## `function greatestCommonDivisor`
1612
1713``` pascal
1814function greatestCommonDivisor(a, b: Int64): Int64;
1915var
2016 temp: Int64;
2117begin
2218 while b <> 0 do
2319 begin
2420 temp := b;
2521 b := a mod b;
2622 a := temp
2723 end;
2824 result := a
2925end;
3026
3127function greatestCommonDivisor_euclidsSubtractionMethod(a, b: Int64): Int64;
3228begin
3329 // działa tylko z dodatnimi liczbami całkowitymi
3430 if (a < 0) then a := -a;
3531 if (b < 0) then b := -b;
3632 // nie wchodź do pętli warunkowej, ponieważ odjęcie zera sprawi, że nie będzie mogła zostać przerwana
3733 if (a = 0) then exit(b);
3834 if (b = 0) then exit(a);
3935 while not (a = b) do
4036 begin
4137 if (a > b) then
4238 a := a - b
4339 else
4440 b := b - a;
4541 end;
4642 result := a;
4743end;
4844```
4945
5046## Zobacz także
5147
5248- [[Least common multiple|Najmniejsza wspólna wielokrotność]]
5349- [[Mod|Operator mod]]
5450- `mpz_gcd` in [[gmp|GMP]] (GNU multiple precision)
5551
5652## zewnętrzne odnośniki
5753
5854- [Przykład rekurencyjny](https://rosettacode.org/wiki/Greatest_common_divisor#Pascal_.2F_Delphi_.2F_Free_Pascal)
5955
6056---
6157*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).*
6258Category: Mathematics

Back to history