Forum Discussion

ESAM_HASHIM's avatar
ESAM_HASHIM
Brass Contributor
Mar 12, 2024

Lowest Common Multiple

It is often very easy to apply the familiar FORMULA (=LCM(A1:A100)to find Lowest Common Multiple for a long wide numbers that included in a column as shown in sheet1 But sometimes I find it's so d...
  • m_tarler's avatar
    m_tarler
    Mar 15, 2024

    SergeiBaklan  Well I took on the challenge and got somewhere with it. (attached).  To do this I created a few Lambda functions:

     

    PrimeFactors256 => returns an array with # of times each of the first 256 prime #s are a factor in the value and the 257th value is either a 1 indicating all the factors were found or the value of the 1 remaining prime factor.  Since the 256th prime# is 1619 this will effectively find the Prime Factors for any number up to 1619^2.


    PrimeFactors => uses PrimeFactors256 but then appends the actual prime numbers and filters the list to only those non-zero and essentially just a nicer/readable output for PrimeFactors256


    LCM_prime => uses Prime Number technique to find the LCM. So this will use PrimeFactors256 and loop through all values inthe array keeping the max repeats of each of the 1st 256 primes and then tack on a unique list of primes above the 256th (those will always be a max of 1 for the valid range) and at the end basically multiple them all together.

     

    This function worked on sheet1 and will "work" on the sheet 2 BUT clearly is outputting a value that is affected by excel's limited number of significant digits.  So assuming it has a good list of primes we could go down that road of 'big number calculation' again.  I'm just happy to get the function to work in what i believe is a pretty efficient manner.