Skip to content

LCM ​

The least common multiple of the arguments.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaLeast common multipleMathWorldLeastCommonMultipleWikidataQ102761Encyclopedia of MathematicsLeast_common_multiplenLableast common multipleBritannicatopic/least-common-multipleFungrimLCM✓Fungrim entryWolfram LanguageLCM!SageMathlcm([$*,])!Rosetta CodeLeast common multiple
LCM(a, b, …)least common multiple of two or more integers.
Typed signatures
TypePackageApplies
(any*) -> numbercompute-enginealways
(any*) -> numbernumber-theoryreplaces compute-enginealways

Domain: Number theory

Details
  • Also called the smallest common multiple: the smallest positive integer that is a multiple of every argument.
  • Paired with GCD by gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b)\cdot\operatorname{lcm}(a,b)=ab.
  • compute-engine discards signs before computing, so lcm⁡(−a,b)=lcm⁡(a,b)\operatorname{lcm}(-a,b)=\operatorname{lcm}(a,b).
  • lcm⁡(0,n)=0\operatorname{lcm}(0,n)=0: 0 absorbs, since 0 is a multiple of everything but nothing else divides back into it.
  • Extends to rationals: lcm⁡(p1/q1,… )=lcm⁡(p1,… )/gcd⁡(q1,… )\operatorname{lcm}(p_1/q_1, \dots) = \operatorname{lcm}(p_1, \dots)/\gcd(q_1, \dots).

Examples

23 more kept as data, checked against the oracles
Basic #
live ↗
Inlcm⁡(4,6)\operatorname{lcm}(4, 6)Out1212

LCM is variadic: it accepts any number of arguments

live ↗
Inlcm⁡(4,6,10)\operatorname{lcm}(4, 6, 10)Out6060
live ↗
Inlcm⁡(2,3,5)\operatorname{lcm}(2, 3, 5)Out3030
Scope #

Over the rationals: the lcm of the numerators over the gcd of the denominators — the smallest positive rational that is an integer multiple of each

live ↗
Inlcm⁡(13,25,37)\operatorname{lcm}(\frac{1}{3}, \frac{2}{5}, \frac{3}{7})Out66

−1+3i=i(3+i)-1 + 3i = i(3 + i): associates share their multiples

live ↗
Inlcm⁡(3+i,−1+3i)\operatorname{lcm}(3+i, -1+3i)Out3+i3+i

Negative integers

live ↗
Inlcm⁡(3,−5,7)\operatorname{lcm}(3, -5, 7)Out105105

Gaussian primes of norm 41 and 13: the LCM is the first-quadrant associate of their product

live ↗
Inlcm⁡(−4+5i,2+3i)\operatorname{lcm}(-4+5i, 2+3i)Out23+2i23+2i

Gaussian rationals: lcm⁡(5+6i, 1+3i)/gcd⁡(10,3)\operatorname{lcm}(5+6i,\,1+3i)/\gcd(10,3)

live ↗
Inlcm⁡(12+35i,13+i)\operatorname{lcm}(\frac{1}{2}+\frac{3}{5}i, \frac{1}{3}+i)Out21+13i21+13i

Big integers: the exact 118-digit LCM, past where a double loses precision

live ↗
Inlcm⁡(20!,10100+3)\operatorname{lcm}(20!, 10^{100}+3)Out3 475 574 297 395 200 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 001 042 672 289 218 560 0003\,475\,574\,297\,395\,200\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,000\,001\,042\,672\,289\,218\,560\,000

Listable: a single list argument threads element-wise against the rest

live ↗
Inlcm⁡(12,[3,7,40])\operatorname{lcm}(12, \bigl\lbrack3, 7, 40\bigr\rbrack)Out[12,84,120]\bigl\lbrack12, 84, 120\bigr\rbrack

A lazy Range, not a materialised List

live ↗
Inlcm⁡(1..10)\operatorname{lcm}(1..10)Out2 5202\,520

Known value · Hand-computed: the smallest number divisible by each of 1 through 10 (same fact as the Applications row below, over List) -- an independent check that a lazy [[Range]] argument is walked element by element

live ↗
InReduceConditions(lcm⁡(a,3)<3a∧−10<a<10,a,Z)\mathrm{ReduceConditions}(\operatorname{lcm}(a, 3)\lt3a∧-10\lt a\lt10, a, ℤ)OutReduceConditions(lcm⁡(3,a)<3a∧−10<a<10,a,Z)\mathrm{ReduceConditions}(\operatorname{lcm}(3, a)\lt3a∧-10\lt a\lt10, a, ℤ)
Applications #

The smallest number divisible by each of 1 through 10

live ↗
Inlcm⁡(1,2,3,4,5,6,7,8,9,10)\operatorname{lcm}(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)Out2 5202\,520

Smallest common multiple of 10 and 15, e.g. for adding 110+115\frac1{10}+\frac1{15}

live ↗
Inlcm⁡(10,15)\operatorname{lcm}(10, 15)Out3030
live ↗
InFoldList(LCM,1,2..10)\mathrm{FoldList}(\mathrm{LCM}, 1, 2..10)Out[1,2,6,12,60,60,420,840,2 520,2 520]\bigl\lbrack1, 2, 6, 12, 60, 60, 420, 840, 2\,520, 2\,520\bigr\rbrack
live ↗
Inln⁡(lcm⁡(1..10))\ln(\operatorname{lcm}(1..10))Out2ln⁡(3)+3ln⁡(2)+ln⁡(35)2\ln(3)+3\ln(2)+\ln(35)
Properties #

gcd⁡(a,b)⋅lcm(a,b)=ab\gcd(a,b)\cdot\mathrm{lcm}(a,b)=ab. See GCD

live ↗
Ingcd⁡(27,81)lcm⁡(27,81)=27×81\gcd(27, 81)\operatorname{lcm}(27, 81)=27×81OutTrue\mathrm{True}

When one number divides the other, the larger is the LCM

live ↗
Inlcm⁡(27,81)\operatorname{lcm}(27, 81)Out8181

Accepts more than two arguments: 2⋅3⋅11⋅52=16502\cdot3\cdot11\cdot5^2=1650

live ↗
Inlcm⁡(6,11,25)=1 650\operatorname{lcm}(6, 11, 25)=1\,650OutTrue\mathrm{True}

Argument order does not matter; coprime inputs multiply to 7070

live ↗
Inlcm⁡(5,7,2)=70\operatorname{lcm}(5, 7, 2)=70OutTrue\mathrm{True}
live ↗
Inln⁡(lcm⁡(1..5)lcm⁡(1..4))\ln(\frac{\operatorname{lcm}(1..5)}{\operatorname{lcm}(1..4)})Outln⁡(5)\ln(5)
Possible issues #

A single argument is returned unchanged

live ↗
Inlcm⁡(5)\operatorname{lcm}(5)Out55

0 absorbs: the LCM with 0 is 0

live ↗
Inlcm⁡(0,5)\operatorname{lcm}(0, 5)Out00

Signs are discarded before computing the LCM

live ↗
Inlcm⁡(−3,7)\operatorname{lcm}(-3, 7)Out2121

An infinite argument has no multiples to take: the call stays unevaluated, as in Wolfram

live ↗
Inlcm⁡(∞,6)\operatorname{lcm}(∞, 6)Outlcm⁡(6,∞)\operatorname{lcm}(6, ∞)
About
Examples48
Checked againstWolfram Language 45 agree3 differSageMath 41 agree1 differ1 unevaluatedSymPy 20 agree13 differ2 unevaluatedmathlib4 9 agree2 errorOscar 5 agree5 errorJulia 9 agree26 errorRust 8 agree2 error
CrosswalkWikipediaMathWorldWikidataEncyclopedia of MathematicsnLabBritannicaFungrimFungrim entry ×26Wolfram LanguageSageMath ×2SymPyOscarJuliaRustRosetta Code

Implementation

mappedwolframpackages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedsympypackages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedsagepackages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedoscarpackages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedjuliapackages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedmathlib4packages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedrustpackages/oracle/src/mappings.ts

compute-engine extends LCM to rationals (lcm of the numerators over the gcd of the denominators); Nemo/Oscar's ZZ conversion only accepts integers, so a rational operand here is a domain gap in the mapping, not a bug on either side.

mappedsagepackages/oracle/src/mappings.ts

See also: GCD