GCD and LCM of an Array

easy · math, gcd, lcm

GCD and LCM of an Array

Given an array of positive integers nums, return a two-element array: [gcd, lcm] of all numbers in the array.

Function signature

func GCDLCM(nums []int) []int64

Example

nums = [6,10,15]
output = [1,30]

Constraints

  • 1 <= len(nums) <= 100_000
  • 1 <= nums[i] <= 1_000_000_000

Notes

  • Use Euclid's algorithm for gcd.
  • Use 64-bit math for lcm.
Run tests to see results
No issues detected