12139 - HA HA HA
raw download clone
C
views 27
,
size 601 b
#include <stdio.h>

int gcd(int n, int m);
int max(int a, int b);

int main(void)
{
    int n, ans;
    int a[1001];

    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%d", &a[i]);
    ans = gcd(a[1], a[2]);
    for(int j=1; j<=n-1; j++)
    {
        for(int k=j+1; k<=n; k++)
            ans = max(ans, gcd(a[j], a[k]));
    }
    printf("%d\n", ans);

    return 0;
}

int gcd(int n, int m)
{
    if(m)
        while((n %= m) && (m %= n));
    return m + n;
}

int max(int a, int b)
{
    if(a > b)
        return a;
    else
        return b;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.