[Solution] Coprime Codeforces Solution | Solution Codeforces
Given an array of positive integers (). Find the maximum value of such that and are coprime, or if no such , exist.
For example consider the array . The maximum value of that can be obtained is , since and are coprime.
Two integers and are coprime if the only positive integer that is a divisor of both of them is (that is, their greatest common divisor is ).
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer () — the length of the array.
The following line contains space-separated positive integers , ,..., () — the elements of the array.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the maximum value of such that and satisfy the condition that and are coprime, or output in case no , satisfy the condition.
For the first test case, we can choose , with sum of indices equal to , since and are coprime.
For the second test case, we can choose and , with sum of indices equal to , since and are coprime.
No comments:
Post a Comment