You are viewing a single comment's thread. Return to all comments →
Swift efficient solution for N < 47:
func leastCommonMultiple(_ n: UInt64) -> UInt64 { var res: UInt64 = 1 let primes: [UInt64] = [2,3,5,7,11,13,17,19,23,29,31,37,41,43] var mcm = Array(1...n) var pi = 0 var mc = 1 while mc <= n { var dc = 1 mc = 1 for i in 0..<mcm.count { if mcm[i] % primes[pi] == 0 { mcm[i] /= primes[pi] } else { dc += 1 } if mcm[i] == 1 { mc += 1 } } if dc > n { pi += 1 } else { res *= primes[pi] } } return res }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #5: Smallest multiple
You are viewing a single comment's thread. Return to all comments →
Swift efficient solution for N < 47: