Problem
Given an array of integers Arr of size N you have to perform the following operation on the array:
- Choose two adjacent elements Arr_i and Arr_{i+1} such that the two elements are not co-prime.
- Delete the two elements and place their LCM at their place only once.
You have to perform the given process as long as there are two adjacent non-co-prime elements and then print the resulting array.
Function description
Complete the function solve: This function takes the following 2 parameters and returns the required answer:
- N: Represents the size of the array Arr
- Arr: Represents the elements of the array Arr
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code
- The first line contains T, which represents the number of test cases.
- For each test case:
- The first line contains N denoting the size of array Arr.
- The second line contains N space-separated values, denoting the elements of Arr.
Output format
For each test case in a separate line, print the resulting array of elements separated by space.
Constraints
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 2 * 10^5
- 1 < Arr_i ≤ 40
Example 1:
- Input: N = 4, Arr = [2, 3, 9, 7]
- Output: [2, 9, 7]