Problem · Array
Find Maximum Possible GCD 🥭
Learn this problemProblem statement
You are given an integer R, and an array A consisting of positive integers.
You can do this operation at most once (possibly zero times):
- Choose any element of the array. Replace it with any integer
X, such that1 ≤ X ≤ R.
Find the maximum possible GCD of the entire array.
Constraints:
Function
findMaximumPossibleGCD(R: int, A: int[]) → intExamples
Example 1
R = 10A = [2, 3, 4]return = 2We can change the second element from 3 to 2. Then GCD of the array becomes gcd(2,2,4)=2, which is the maximum possible.
Constraints
2 ≤ N ≤ 10^5 (N is length of array)1 ≤ R ≤ 10^51 ≤ Ai ≤ 10^5