Code: 05


 Question 5

 

Minimum number

You are given N numbers A1, A2, A3…..AN. find the minimum number P(P>1) such that P is a co-prime with all of the given numbers

Note: two integers a and n are said to be co-prime if the only positive integer (factor) that divides both of them is 1.

Function description

Complete the solve function provided in the editor. The function takes the following 2 parameters and returns the minimum number p.

·        N: represents the number of elements

·        A[]: represents the array of elements

Input format

·        First line: T (number of test cases)

·        For each test case:

o   First line: N(number of integers)

o   Second line: N space separated integers, A1, A2, A3…AN.

Output format

Print T lines each containing one integer denoting the answer of the corresponding test case.

Constraints

1 ≤ T ≤ 5

1 ≤ N ≤ 105

1 ≤ AI ≤ 106



 

Explanation

Testcase 1:

GCD(5,2) = 1

GCD(7,2) = 1

GCD(25,2) = 1

Hence, the smallest number which is co-prime to all of the given number is 2.

Testcase 2:

GCD(1,5) = 1

GCD(2,5) = 1

GCD(3,5) = 1

GCD(4,5) = 1

Hence, the smallest number which is co-prime to all of the given number is 5

Testcase 3:

GCD(2,3) = 1

Hence, the smallest number which is co prime to all the given numbers is 3.

GCD(a,b) stands for the Greatest Common Divisor of number a and b.

No comments:

Post a Comment