Sign in Join
Wiki copytemporary

Greatest common divisor/pl: what changed

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

Title: Greatest common divisor/pl

OldNewLine
1+<div style="font-size:1.88em;margin:0.75em 0;">
2+
3+Największy wspólny dzielnik
4+
5+</div>
6+
7+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.
8+
9+There are many methods to calculate this. For example, the division-based Euclidean algorithm version may be programmed:
10+
11+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.
12+
13+Istnieje wiele metod obliczania największego wspólnego dzielnika dwóch liczb. Można na przykład zaprogramować wersję algorytmu Euklidesa opartego na dzieleniu:
14+
15+## `function greatestCommonDivisor`
16+
17+``` pascal
18+function greatestCommonDivisor(a, b: Int64): Int64;
19+var
20+ temp: Int64;
21+begin
22+ while b <> 0 do
23+ begin
24+ temp := b;
25+ b := a mod b;
26+ a := temp
27+ end;
28+ result := a
29+end;
30+
31+function greatestCommonDivisor_euclidsSubtractionMethod(a, b: Int64): Int64;
32+begin
33+ // działa tylko z dodatnimi liczbami całkowitymi
34+ if (a < 0) then a := -a;
35+ if (b < 0) then b := -b;
36+ // nie wchodź do pętli warunkowej, ponieważ odjęcie zera sprawi, że nie będzie mogła zostać przerwana
37+ if (a = 0) then exit(b);
38+ if (b = 0) then exit(a);
39+ while not (a = b) do
40+ begin
41+ if (a > b) then
42+ a := a - b
43+ else
44+ b := b - a;
45+ end;
46+ result := a;
47+end;
48+```
49+
50+## Zobacz także
51+
52+- [[Least common multiple|Najmniejsza wspólna wielokrotność]]
53+- [[Mod|Operator mod]]
54+- `mpz_gcd` in [[gmp|GMP]] (GNU multiple precision)
55+
56+## zewnętrzne odnośniki
57+
58+- [Przykład rekurencyjny](https://rosettacode.org/wiki/Greatest_common_divisor#Pascal_.2F_Delphi_.2F_Free_Pascal)
59+
60+---
61+*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).*
62+Category: Mathematics

Back to history