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