You are on page 1of 1

import java.io.

*; // for handling input/output


import java.util.*; // contains Collections framework

// don't change the name of this class


// you can add inner classes if needed
class Main {
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int findGCD(int arry[], int n)
{
int result = arry[0];
for (int element: arry){
result = gcd(result, element);

if(result == 1)
{
return 1;
}
}
return result;
}

public static void main (String[] args) {


Scanner sc=new Scanner(System.in);
int[] nums=new int[2];
for(int i=0;i<3;i++){
nums[i]=sc.nextInt();
}
int N=nums[0];
int R=nums[1];
int[] arry=new int[N];
for(int j=0;j<N;j++){
arry[j]=sc.nextInt();
}

int temp=1;
for(int k=1;k<=R ;k++){
int G= findGCD(arry,N);
if(G>temp){
temp=G;
}
}
System.out.println(temp);

}
}

You might also like