715
|
1 function l = lcm (a, ...) |
|
2 |
|
3 # lcm (a) returns the least common multiple of the entries of the |
|
4 # integer vector a. |
|
5 # lcm (a1, ..., ak) is the same as lcm([a1, ..., ak]). |
|
6 |
|
7 # Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 16, 1994 |
|
8 # Copyright Dept of Statistics and Probability Theory TU Wien |
|
9 |
|
10 if (nargin > 1) |
|
11 va_start; |
|
12 for k=2:nargin; |
|
13 a = [a, va_arg()]; |
|
14 endfor |
|
15 endif |
|
16 |
|
17 if (round(a) != a) |
|
18 error("lcm: all arguments must be integer"); |
|
19 endif |
|
20 |
|
21 if (any(a) == 0) |
|
22 l = 0; |
|
23 else |
|
24 a = abs(a); |
|
25 l = a(1); |
|
26 for k=1:(length(a)-1) |
|
27 l = l * a(k+1) / gcd(l, a(k+1)); |
|
28 endfor |
|
29 endif |
|
30 |
|
31 endfunction |
|
32 |