Greatest common divisor/pl
English · Français · Polski · Suomi · Русский
Największy wspólny dzielnik
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.
Istnieje wiele metod obliczania największego wspólnego dzielnika dwóch liczb. Można na przykład zaprogramować wersję algorytmu Euklidesa opartego na dzieleniu:
function greatestCommonDivisor
function greatestCommonDivisor(a, b: Int64): Int64;
var
temp: Int64;
begin
while b <> 0 do
begin
temp := b;
b := a mod b;
a := temp
end;
result := a
end;
function greatestCommonDivisor_euclidsSubtractionMethod(a, b: Int64): Int64;
begin
// działa tylko z dodatnimi liczbami całkowitymi
if (a < 0) then a := -a;
if (b < 0) then b := -b;
// nie wchodź do pętli warunkowej, ponieważ odjęcie zera sprawi, że nie będzie mogła zostać przerwana
if (a = 0) then exit(b);
if (b = 0) then exit(a);
while not (a = b) do
begin
if (a > b) then
a := a - b
else
b := b - a;
end;
result := a;
end;Zobacz także
- Najmniejsza wspólna wielokrotność
- Operator
mod mpz_gcdin GMP (GNU multiple precision)
zewnętrzne odnośniki
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.
Edited on wiki.freepascal.org by 1 person, 2023
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Slawek | Tłumaczenie na j. polski |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
