Maximum GCD Pair
Medium Accuracy: 20.0% Submissions: 10 Points: 4

Given an array of integers find the pair in the array with maximum GCD. Find the maximum possible GCD.

Example 1:

Input: N = 5, a[] = {1, 2, 3, 4, 5}
Output: 2
Explanation: Maximum gcd is GCD(2, 4)
= 2.

​Example 2:

Input: N = 3, a[] = {3, 5, 2}
Output: 1
Explanation: Maximum gcd is 1.

Your Task:  
Your task is to complete the function MaxGcd() which takes the N and list of N elements as inputs and returns the answer.


Expected Time Complexity: O(N * log N)
Expected Auxiliary Space: O(max(ai))

Constraints:
1 ≤ N ≤ 105
1 ≤ ai ≤ 10
5
 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.