Documentation Center

  • Trials
  • Product Updates


Least common multiple




L = lcm(A,B) returns the least common multiples of the elements of A and B.


expand all

Least Common Multiples of Double Array and a Scalar

A = [5 17; 10 60];
B = 45;
L = lcm(A,B)
L =

    45   765
    90   180

Least Common Multiples of Unsigned Integers

A = uint16([255 511 15]);
B = uint16([15 127 1023]);
L = lcm(A,B)
L =

    255  64897   5115

Input Arguments

expand all

A,B — Input valuesscalars, vectors, or arrays of real, positive integer values

Input values, specified as scalars, vectors, or arrays of real, positive integer values. A and B can be any numeric type, and they can be of different types within certain limitations:

  • If A or B is of type single, then the other can be of type single or double.

  • If A or B belongs to an integer class, then the other must belong to the same class or it must be a double scalar value.

A and B must be the same size or one must be a scalar.

Example: [20 3 13],[10 6 7]

Example: int16([100 30 200]),int16([20 15 9])

Example: int16([100 30 200]),20

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

expand all

L — Least common multiplereal, positive integer values

Least common multiple, returned as an array of real positive integer values. L is the same size as A and B, and it has the same type as A and B. If A and B are of different types, then L is returned as the nondouble type.

See Also

Was this topic helpful?