Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Elementary Functions > Discrete mathematics > lcm

lcm

least common (positive) multiple of integers or of polynomials

Syntax

pp = lcm(p)
[pp, fact] = lcm(p)

Arguments

p

matrix of polynomials (type 2), or of decimal or encoded integers (types 1 or 8).

pp

a polynomial or a decimal integer: Positive Least Common Multiple of p components.

fact

matrix of polynomials, or of decimal integers (type 1), with the size of p, such that fact(i)= pp./p(i).

Description

pp=lcm(p) computes the LCM pp of p components.

If p are polynomials, pp is a polynomial and fact is also a matrix of polynomials.

If p is a set of integers,

  • if they are encoded integers, they are then converted into decimal integers before processing.
  • Any int64 or uint64 input |integers| > 2^53 will be truncated and lcm() will return a wrong result.
  • If some of them are negative, the returned value pp of their LCM is always positive.

The least common multiple of an array p of real numbers can be obtained by converting it to a polynomial before calling lcm, through p = inv_coeff(p, 0).

Examples

With polynomials:

s = %s;
p = [s , s*(s+1) , s^2-1]
[pp, fact] = lcm(p)
p .* fact == pp
--> p = [s , s*(s+1) , s^2-1]
 p  =
           2       2
   s   s +s   -1 +s

--> [pp, fact] = lcm(p)
 fact  =
       2
  -1 +s   -1 +s   s

 pp  =
       3
  -s +s

--> p .* fact == pp
 ans  =
  T T T

With encoded integers:

// Prime numbers: 2  3  5  7  11  13  17  19  23  29  31  37  41  43  47
V = int16([2*3 3*7 ; 7*5  3*5])
[pp, fact] = lcm(V)
--> V = int16([2*3 3*7 ; 7*5  3*5])
 V  =
   6  21
  35  15

--> [pp, fact] = lcm(V)
 pp  =
   210.

 fact  =
   35.   10.
   6.    14.

With decimal integers:

V = [2*3 3*7 ; 7*5  3*5]
[pp, fact] = lcm(V)

With big integers:

V = [3*2^51 , 3*5]
[pp, fact] = lcm(V)    // OK
--> V = [3*2^51 , 3*5]
 V  =
   6.755D+15   15.

--> [pp, fact] = lcm(V)
 fact  =
   5.   2.252D+15

 pp  =
   3.378D+16

When the numerical encoding is overflown, truncature occurs and results turn wrong:

V = [3*2^52 , 3*5]
[pp, fact] = lcm(V)
--> V = [3*2^52 , 3*5]
 V  =
   1.351D+16   15.

--> [pp, fact] = lcm(V)
 fact  =
   15.   1.351D+16

 pp  =
   2.027D+17

See also

  • gcd — Greatest (positive) Common Divisor
  • bezout — Bezout法により、2つの多項式または2つの整数の最大公約数を計算します
  • factor — 素因数分解関数

History

VersionDescription
6.0.1 For input integers possibly negative, the returned LCM is now always positive.
6.0.2
  • int64 and uint64 input encoded integers are now supported.
  • p can now be a matrix of any shape, not necessarily a row.
  • When p is a matrix of encoded or decimal integers, computations are now performed in floating point instead of int32 format. pp and fact are now decimal integers (instead of int32 integers).
Report an issue
<< gcd Discrete mathematics nchoosek >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:53:18 CET 2020