Difference between revisions of "Least common multiple"

From Lazarus wiki
Jump to navigationJump to search
 
Line 5: Line 5:
 
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 lang="pascal" inline>function leastCommonMultiple</syntaxhighlight> ==
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
Line 14: Line 14:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{Note|[[Greatest common divisor#function greatestCommonDivisor|<syntaxhighlight lang="pascal" enclose="none">function greatestCommonDivisor</syntaxhighlight>]] must be at least declared before this function.}}
+
{{Note|[[Greatest common divisor#function greatestCommonDivisor|<syntaxhighlight lang="pascal" inline>function greatestCommonDivisor</syntaxhighlight>]] must be at least declared before this function.}}
  
 
== see also ==
 
== see also ==
  
 
* [[Greatest common divisor|greatest common divisor]]
 
* [[Greatest common divisor|greatest common divisor]]
* <syntaxhighlight lang="pascal" enclose="none">mpz_lcm</syntaxhighlight> in [[gmp|GMP]] (GNU multiple precision)
+
* <syntaxhighlight lang="pascal" inline>mpz_lcm</syntaxhighlight> in [[gmp|GMP]] (GNU multiple precision)
  
 
[[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;
Light bulb  Note: function greatestCommonDivisor must be at least declared before this function.

see also