Tap here to switch tabs
Problem
Submissions

Problem: Replace Non-Coprime Numbers in Array

med
30 min
Try to solve the Replace Non-Coprime Numbers in Array problem.

Statement

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 x and y are non coprime if their greatest common divisor satisfies $ ext{GCD}(x, y) > 1$.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • The test cases are generated such that the values in the final array are less than or equal to 10810^8.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Replace Non-Coprime Numbers in Array

med
30 min
Try to solve the Replace Non-Coprime Numbers in Array problem.

Statement

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 x and y are non coprime if their greatest common divisor satisfies $ ext{GCD}(x, y) > 1$.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • The test cases are generated such that the values in the final array are less than or equal to 10810^8.