You are given an array of integers nums. Perform the following steps until no two adjacent elements are non coprime:
Find any two adjacent numbers in nums that are non coprime.
Replace these two numbers with their least common multiple ($ ext{LCM}$).
Repeat this process as long as there are adjacent non coprime numbers.
Return the final modified array. It can be shown that replacing adjacent non coprime numbers in any valid order will always produce the same final result.
Note: Two integers
xandyare non coprime if their greatest common divisor satisfies $ ext{GCD}(x, y) > 1$.
Constraints:
nums.length
nums[i]
The test cases are generated such that the values in the final array are less than or equal to
You are given an array of integers nums. Perform the following steps until no two adjacent elements are non coprime:
Find any two adjacent numbers in nums that are non coprime.
Replace these two numbers with their least common multiple ($ ext{LCM}$).
Repeat this process as long as there are adjacent non coprime numbers.
Return the final modified array. It can be shown that replacing adjacent non coprime numbers in any valid order will always produce the same final result.
Note: Two integers
xandyare non coprime if their greatest common divisor satisfies $ ext{GCD}(x, y) > 1$.
Constraints:
nums.length
nums[i]
The test cases are generated such that the values in the final array are less than or equal to