Fast Arithmetic Functions

sage.arith.functions.LCM_list(v)[source]

Return the LCM of an iterable v.

Elements of v are converted to Sage objects if they aren’t already.

This function is used, e.g., by lcm().

INPUT:

  • v – an iterable

OUTPUT: integer

EXAMPLES:

sage: from sage.arith.functions import LCM_list
sage: w = LCM_list([3,9,30]); w
90
sage: type(w)
<class 'sage.rings.integer.Integer'>
>>> from sage.all import *
>>> from sage.arith.functions import LCM_list
>>> w = LCM_list([Integer(3),Integer(9),Integer(30)]); w
90
>>> type(w)
<class 'sage.rings.integer.Integer'>
from sage.arith.functions import LCM_list
w = LCM_list([3,9,30]); w
type(w)

The inputs are converted to Sage integers:

sage: w = LCM_list([int(3), int(9), int(30)]); w
90
sage: type(w)
<class 'sage.rings.integer.Integer'>
>>> from sage.all import *
>>> w = LCM_list([int(Integer(3)), int(Integer(9)), int(Integer(30))]); w
90
>>> type(w)
<class 'sage.rings.integer.Integer'>
w = LCM_list([int(3), int(9), int(30)]); w
type(w)
sage.arith.functions.lcm(a, b=None)[source]

The least common multiple of a and b, or if a is a list and b is omitted the least common multiple of all elements of a.

Note that LCM is an alias for lcm.

INPUT:

  • a, b – two elements of a ring with lcm or

  • a – list; tuple or iterable of elements of a ring with lcm

OUTPUT:

First, the given elements are coerced into a common parent. Then, their least common multiple in that parent is returned.

EXAMPLES:

sage: lcm(97, 100)
9700
sage: LCM(97, 100)
9700
sage: LCM(0, 2)
0
sage: LCM(-3, -5)
15
sage: LCM([1,2,3,4,5])
60
sage: v = LCM(range(1, 10000))   # *very* fast!
sage: len(str(v))
4349
>>> from sage.all import *
>>> lcm(Integer(97), Integer(100))
9700
>>> LCM(Integer(97), Integer(100))
9700
>>> LCM(Integer(0), Integer(2))
0
>>> LCM(-Integer(3), -Integer(5))
15
>>> LCM([Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)])
60
>>> v = LCM(range(Integer(1), Integer(10000)))   # *very* fast!
>>> len(str(v))
4349
lcm(97, 100)
LCM(97, 100)
LCM(0, 2)
LCM(-3, -5)
LCM([1,2,3,4,5])
v = LCM(range(1, 10000))   # *very* fast!
len(str(v))