Implement a Range-Based LCM Calculator - Ideas?

Tell us what’s happening:

Hello,
I am curious what you think of my idea:

A - take the upper value and create multiples (multiply it by [2 … upperValue -1] in a loop)

B- in another loop: check for the multiple, if it is divisible without rest by the other numbers of the submitted range

C-- if yes, the muliple is the LCM
D-- if no, take the next multiple of the upper value (go to C)

What do you think of that and are there any other ideas out there?

I already implemented the code successfully.

Your code so far


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Implement a Range-Based LCM Calculator - Implement a Range-Based LCM Calculator

Let me rephrase that:

  • I am creating multiples of the highest number in the range
  • I am checking the multiple (starting with the lowest) if it is divisible without rest with all the numbers in the range. if yes, the multiple is the LCM

that would work, you could also research LCM and GCD algorithms

1 Like