Given an array of N elements, find the minimum number of insertions to convert the given array into a co-prime array pair-wise.
Input:
The first line of the input contains an integer T, denoting number of test cases. The first line of each test case contains an integer N denoting the size of the array. The second line of each test cases N space separated integers.
Output:
For each test case, print a single line of output containing minimum no. of insertions.
Constraints:
1<=T<=100
1<=N<=100
1<=arr<=1000
Example:
Input:
2
3
2 7 28
3
5 10 20
Output:
1
2
Explanation:
Testcase 1:
Here, 1st pair = {2, 7} are co-primes( gcd(2, 7) = 1).
2nd pair = {7, 28} are not co-primes, insert 9
between them. gcd(7, 9) = 1 and gcd(9, 28) = 1.
Testcase 2:
Here, there is no pair which are co-primes.
Insert 7 between (5, 10) and 1 between (10, 20).
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.
bruceewayne | 119 |
rajupraaa1234 | 110 |
SUZAKU | 104 |
yash_sharan | 104 |
Core_Ka_Bachha | 99 |
mr_kksparrow | 433 |
manvirag982 | 302 |
rajupraaa1234 | 245 |
Exception_404 | 244 |
snow_den_ | 236 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |