22 lines
303 B
Go
22 lines
303 B
Go
package q02
|
|
|
|
func gcd(a, b int64) int64 {
|
|
for b != 0 {
|
|
a, b = b, a%b
|
|
}
|
|
return a
|
|
}
|
|
|
|
func lcm(nums []int) int64 {
|
|
result := int64(nums[0])
|
|
for i := range nums {
|
|
n := int64(nums[i])
|
|
result = result * n / gcd(result, n)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func solveP1(ships []int) int64 {
|
|
return lcm(ships)
|
|
}
|