Smallest Common Multiple Feedback

continuing my previous post …

the reduction due to one common prime factor must be carried out for every common prime factor - this leads to two ways to restate lcm

lcm(a,b) is the product of the bigger power of each prime factor from factorizations of a and b

the bigger prime powers from the factorizations of 342 and 20 are

2^2 (from 20), 3^2 (from 342), 5^1 (from 20), 19^1 (from 342) - so

lcm(342, 20) = 2**2 * 3**2 * 5 * 19 = 3420

you used this first restatement in your solution just not iteratively

computationally this still relies on prime factorization which is quite expensive

another way to restate lcm(a,b) is to note the product of all the common prime factors of two numbers is their gcd - so

lcm(a,b) = a*b / gcd(a,b)

so

lcm(342, 20) = 342*20 / gcd(342, 20) = 3420

what’s interesting about the second restatement is it does not directly use prime factorizations

if there was a simpler way to calculate the gcd without factorization we’d be golden