0

I would like to calculate the Least Common Multiple of the 100 first numbers. I've tried with

LCM[Table[i, {i, 10}]]

But it produces a list instead of the right answer, a single number.

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

It seems that LCM doesn't like to get a list as the input.

What's the proper way to do it?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
skan
  • 193
  • 5

1 Answers1

1

LCM takes a Sequence of numbers (not a List of numbers) as input.

input = Table[i, {i, 100}];

You can use input in LCM in a number of ways:

LCM @@ input (* replace the `Head` of `input` by `LCM` *)
LCM[Sequence@@input] (* replace the `Head` of `input` by `Sequence` *)
input /. List -> LCM
input2 = input; ReplacePart[input2, 0 -> LCM]
input3 = input; input3[[0]]=LCM; input3
input4 = input; MapAt[LCM &, input4, {0}]

all give

69720375229712477164533808935312303556800
kglr
  • 394,356
  • 18
  • 477
  • 896