Here is the Question. Find the largest GCD of the input variable with the values of an array.
Inputs are as follows:- First-line contains two integers, N and Q.
Second-line contains N integers which form the arr[].
Next, Q lines contain an integer M, the time in seconds she wishes to go back.
#include <stdio.h>
int main(){
int n,q;
scanf("%d %d", &n,&q);
int a[n];
int gcdn[n];
for (int i = 0;i < n; i++) {
scanf("%d",&a[i]); }
while (q>0){
q--;
int x;
int max = 0;
scanf("%d",&x);
max = gcd(a[0],x);
for(int i=0;i<n;i++) {
int t = gcd(a[i],x);
if(t > max)
max = t;
}
printf("%d \n",max);
}
}
int gcd (int a, int b) {
if (b==0)
return a;
else
return gcd(b, a%b);
}
How can I make this code better in terms of competitive programming? And what other languages can make this code better and more efficient?