Files
advent-of-code-go/mathy/lcm.go
T
2024-07-25 18:15:56 -04:00

19 lines
261 B
Go

package mathy
func LeastCommonMultiple(i, j int) int {
gcd := GreatestCommonMultiple(i, j)
return (i * j) / gcd
}
func GreatestCommonMultiple(i, j int) int {
if j > i {
i, j = j, i
}
if j == 0 {
return i
}
return GreatestCommonMultiple(j, i%j)
}