Maximum GCD

1

1 votes
GCD, Number Theory, C++, Math
Problem

You are given an array A of length N. You can perform the following operation at most once.

  • Choose any element of the array and replace it with X where 1XM.

Find the maximum possible GCD of the array after performing the operation.

Input Format:

  • The first line contains an integer T, which denotes the number of test cases. 
  • The first line of each test case contains two integers N and M.
  • The second line of each test case contains N space-separated integers, elements of array A.

Output Format:

For each test case, print the maximum possible GCD of the array after performing the operation at most once.

Constraints:

1T101N,M1051A[i]105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For first test case:
We can replace 5 with 4. The maximum possible GCD is 2.

For second test case:
We do not need to replace any element. The maximum possible GCD is 5.

Editor Image

?