Difference between revisions of "Least common multiple"

From Lazarus wiki
Jump to navigationJump to search
m
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.
  
==Function LeastCommonMultiple==
+
== <syntaxhighlight lang="pascal" enclose="none">function leastCommonMultiple</syntaxhighlight> ==
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
function LeastCommonMultiple(a, b: Int64): Int64;
+
function leastCommonMultiple(a, b: Int64): Int64;
 
begin
 
begin
   result := b * (a div GreatestCommonDivisor(a, b))
+
   result := b * (a div greatestCommonDivisor(a, b));
end;
+
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{Note| Function [[Greatest common divisor#Function GreatestCommonDivisor |GreatestCommonDivisor ]] must be defined before this function}}
+
{{Note|[[Greatest common divisor#function greatestCommonDivisor|<syntaxhighlight lang="pascal" enclose="none">function greatestCommonDivisor</syntaxhighlight>]] must be at least declared before this function.}}
  
 +
== see also ==
  
== See also ==
+
* [[Greatest common divisor|greatest common divisor]]
 +
* <syntaxhighlight lang="pascal" enclose="none">mpz_lcm</syntaxhighlight> in [[gmp|GMP]] (GNU multiple precision)
  
* [[Greatest common divisor]]
+
[[Category:Mathematics]]
<br>
 

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;
Light bulb  Note: function greatestCommonDivisor must be at least declared before this function.

see also