Difference between revisions of "Least common multiple"
From Lazarus wiki
Jump to navigationJump to searchm |
(add Category:Mathematics) |
||
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" enclose="none">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" enclose="none">function greatestCommonDivisor</syntaxhighlight>]] must be at least declared before this function.}} |
+ | == see also == | ||
− | == | + | * [[Greatest common divisor|greatest common divisor]] |
+ | * <syntaxhighlight lang="pascal" enclose="none">mpz_lcm</syntaxhighlight> in [[gmp|GMP]] (GNU multiple precision) | ||
− | + | [[Category:Mathematics]] | |
− |
Revision as of 18:03, 13 February 2018
│
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)