Untitled
raw download clone
C
views 33
,
size 655 b
#include<stdio.h>
int GCD(int a, int b)//a>b
{
    if( b==0 )
        return a;
    else
        return GCD( b, a%b );
}
int main(void)
{
    int A[1001];
    int fir[100], n, max, min;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &A[i]);  //array
    }
    for(int j=0; j<n; j++){
            for(int p=1; p<=n; p++){
                fir[p] = GCD(A[j], A[j+p]); //wrong!!
            }//fir[1] ~ fir[4]
    }

    for(int k=0; k<n; k++){
        if(fir[k]<fir[k+1])
        {
            max = fir[k+1];
            min = fir[k];
        }
    }
    printf("%d\n", GCD(max,min));

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.