Răspuns:
#include<bits/stdc++.h>
int v[10017], n;
int gcd(int x, int y)
{
if(x == 0)
return y;
return gcd(y % x, x);
}
int findGcd(int v[], int n)
{
int cmmdc = v[1];
for(int i = 2; i <= n; ++ i)
{
cmmdc = gcd(v[i], cmmdc);
if(cmmdc == 1)
return 1;
}
return cmmdc;
}
int main()
{
std::cin >> n;
for(int i = 1; i <= n; ++ i)
std::cin >> v[i];
std::cout << findGcd(v, n);
return 0;
}
Explicație: