This site is supported by donations to The OEIS Foundation.

# Template:LCM/doc

Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:LCM. [<Edit> Template:LCM]

[⧼Purge⧽ Template:LCM/doc]

The {{LCM}} mathematical function template returns the least common multiple (LCM) of two nonzero integers as a positive integer. An error message is returned when any parameter is not a nonzero integer (currently returns 0 if one parameter is 0 while the other is nonzero, the default value of each parameter being 1) or when the LCM calculation is too complex (this implementation of {{LCM}} uses the {{GCD}} mathematical function template, which currently returns 0 when its limit of ten iterations of the Euclidean algorithm is exceeded, causing a division by zero error in {{LCM}}).

## Usage

{{LCM|a nonzero integer|a nonzero integer}}

or

{{lcm|a nonzero integer|a nonzero integer}}

## Valid input

Two nonzero integers as parameters.

## Examples

Examples with valid input (returns LCM, unless the iterations limit of the Euclidean algorithm is exceeded in the GCD calculation)

Code Result Comment
{{LCM|1}} 1
{{LCM|6}} 6
{{LCM|16|6}} 48
{{LCM|16|32}} 32
{{LCM|25|625}} 625
{{LCM|544|119}} 3808
{{LCM|119|544}} 3808
{{LCM|-544|119}} 3808
{{LCM|544|-119}} 3808
{{LCM|-544|-119}} 3808
{{LCM|2089|3571}} 7459819
{{LCM|3571|2089}} 7459819
{{LCM|20891|35713}} 746080283
{{LCM|308911|355717}} 109884894187
{{LCM|6534273|3557172}} Expression error: Unexpected < operator.
{{LCM|{{Fibonacci|12}}|{{Fibonacci|11}}}} = {{LCM|144|89}} 12816
{{LCM|{{Fibonacci|13}}|{{Fibonacci|12}}}} = {{LCM|233|144}} 33552
{{LCM|{{Fibonacci|14}}|{{Fibonacci|13}}}} = {{LCM|377|233}} 87841
{{LCM|{{Fibonacci|15}}|{{Fibonacci|14}}}} = {{LCM|610|377}} Expression error: Unexpected < operator.
{{LCM|{{Fibonacci|16}}|{{Fibonacci|15}}}} = {{LCM|987|610}} Expression error: Unexpected < operator.
{{LCM|{{Fibonacci|17}}|{{Fibonacci|16}}}} = {{LCM|1597|987}} Expression error: Unexpected < operator.
{{LCM|{{Fibonacci|18}}|{{Fibonacci|17}}}} = {{LCM|2584|1597}} Expression error: Unexpected < operator.
{{LCM|{{Fibonacci|19}}|{{Fibonacci|18}}}} = {{LCM|4181|2584}} Expression error: Unexpected < operator.
{{LCM|{{Fibonacci|20}}|{{Fibonacci|19}}}} = {{LCM|6765|4181}} Expression error: Unexpected < operator.
{{LCM|20891|35713}} 746080283
{{LCM|{{expr|2*3*5*7*11*13*17*19}}|{{expr|7*17*101*113}}}} 110702561970
{{LCM|{{expr|5^2*7*13*17}}|{{expr|5*7*17*23}}}} 889525
{{mpf|{{LCM|{{expr|5^2*7*13*17}}|{{expr|5*7*17*23}}}}}} 5^2 * 7^1 * 13^1 * 17^1 * 23^1

Examples with special input (degenerate cases) giving special output

Code Result Comment
{{LCM}} 1 LCM of empty product (1)
{{LCM|0}} 0
{{LCM|0|6}} 0
{{LCM|6|0}} 0

Examples with invalid input (returns an error message)

Code Result Comment
{{LCM|ten|fifteen}} Expression error: Unrecognized word "ten".
{{LCM|6.74|9}} Expression error: Unexpected < operator.
{{LCM|2/3|4/9}} Expression error: Unexpected < operator.
{{LCM|0|0}} Division by zero.

## Code

Version with reduced nesting levels (those are limited by MediaWiki!):

```
{{#expr: ( abs ( {{{1|1}}} ) ) / {{GCD| ( {{{1|1}}} ) | ( {{{2|1}}} ) }} * ( abs ( {{{2|1}}} ) ) }}

```

Previous version:

```
{{ifint| ( {{{1|empty}}} )
| {{ifint| ( {{{2|empty}}} )
| {{#ifexpr: ( {{{1}}} ) * ( {{{2}}} ) = 0
| {{error| LCM error: Integers must be nonzero }}
| {{expr| ( abs ( {{{1}}} ) ) / {{GCD| ( {{{1}}} ) | ( {{{2}}} ) }} * ( abs ( {{{2}}} ) ) }}
}}
| {{error| LCM error: Arguments must be nonzero integers }}
}}
| {{error| LCM error: Arguments must be nonzero integers }}
}}

```