# least common multiplier

• 03-11-2003
Jaguar
least common multiplier
I've ever writen a function returning `greatest common divisor'.
But now I need `least common multiplier' to carry on my project.
Please anyone suggest me its concept. In order that I can write it by myself. :D

Any help would be much appreciated.
Thanks,
• 03-11-2003
Hammer
Are you having problems with the maths or the code?
• 03-14-2003
Jaguar
I have problem with math.
I only need its concept.
I want to write it by myself. :D
Sorry in late reply.

Thanks,
• 03-14-2003
Dave_Sinkula
• 03-14-2003
tigs
To work out by brute force:

Start looping at the lowest of the two given numbers multiplied by two. Loop every number up to the product of the two numbers.
In the loop, if you modulus the current tested number by the first number and the second number, and both are 0, return the current tested number.
After the loop return the product of the two numbers.
• 03-14-2003
Magos
Split the number into prime numbers. Then, for each prime number, pick the one with the most amount and multiply that to the answer.
If that sounded too weird (I guess it did) then look at this:

1500 = 2 * 2 * 3 * 5 * 5 * 5
126 = 2 * 3 * 3 * 7

For 2:s, the first one have 2 and the second has 1. 2 > 1 so we pick 2.

For 3:s, the first one has 1 and the second has 2. 1 < 2 so we pick 2.

For 5:s, the first one has 3 and the second one has 0. 3 > 0 so we pick 3.

For 7:s, the first one has 0 and the second one has 1. 0 < 1 so we pick 1.

The least common multiplier is:
2^2 * 3^2 * 5^3 * 7^1 = 31500

test:
31500 = 1500 * 21
31500 = 126 * 250

21 = 7 * 3
neither 7 nor 3 splits 250

31500 is the least common multiplier!
• 03-14-2003
Jaguar
Thanks all of you. That is what I need.