Difference between revisions of "Least common multiple"
From Free Pascal wiki
Jump to navigationJump to search(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Least common multiple}} | {{Least common multiple}} | ||
− | The least common multiple of two integers a and b is the smallest positive integer that is divisible by both a and b. | + | The least common multiple of two integers <math>a</math> and <math>b</math> is the smallest positive integer that is divisible by both <math>a</math> and <math>b</math>. |
For example: for 12 and 9 then least common multiple is 36. | For example: for 12 and 9 then least common multiple is 36. | ||
− | == | + | == <syntaxhighlight lang="pascal" inline>function leastCommonMultiple</syntaxhighlight> == |
− | <syntaxhighlight> | + | <syntaxhighlight lang="pascal"> |
− | function | + | function leastCommonMultiple(a, b: Int64): Int64; |
begin | begin | ||
− | result := b * (a div | + | result := b * (a div greatestCommonDivisor(a, b)); |
− | end; | + | end; |
</syntaxhighlight> | </syntaxhighlight> | ||
− | {{Note| | + | {{Note|[[Greatest common divisor#function greatestCommonDivisor|<syntaxhighlight lang="pascal" inline>function greatestCommonDivisor</syntaxhighlight>]] must be at least declared before this function.}} |
+ | == see also == | ||
− | + | * [[Greatest common divisor|greatest common divisor]] | |
− | + | * <syntaxhighlight lang="pascal" inline>mpz_lcm</syntaxhighlight> in [[gmp|GMP]] (GNU multiple precision) | |
− | * [[Greatest common divisor]] | ||
− | |||
[[Category:Mathematics]] | [[Category:Mathematics]] |
Latest revision as of 17:13, 6 August 2022
│
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
The least common multiple of two integers [math]\displaystyle{ a }[/math] and [math]\displaystyle{ b }[/math] is the smallest positive integer that is divisible by both [math]\displaystyle{ a }[/math] and [math]\displaystyle{ b }[/math].
For example: for 12 and 9 then least common multiple is 36.
function leastCommonMultiple
function leastCommonMultiple(a, b: Int64): Int64;
begin
result := b * (a div greatestCommonDivisor(a, b));
end;
Note:
function greatestCommonDivisor
must be at least declared before this function.see also
- greatest common divisor
mpz_lcm
in GMP (GNU multiple precision)