hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor

#include<stdio.h>

#include<string.h>

#include<math.h>

int flag[100005];

int a[100005];

int main()

{

    int sb;

    scanf("%d", &sb);

    int u;

    for (u = 1; u <= sb; u++)

    {

        int n, i;

        int maxn = -999999999;

        scanf("%d", &n);

        memset(flag, 0, sizeof(flag));

        for (i = 1; i <= n; i++)

        {

            scanf("%d", &a[i]);

            if (a[i] >= maxn) maxn = a[i];

        }

        for (i = 1; i <= n; i++)

        {

            int j;

            for (j = 1; j *j <= a[i]; j++)

            {

                if (a[i] % j == 0 && j*j < a[i]) flag[j]++, flag[a[i] / j]++;

                else if (a[i] % j == 0 && j*j == a[i]) flag[j]++;

            }

        }

        int ans;

        for (i = maxn; i >= 1; i--)

        {

            if (flag[i] >= 2) { ans = i; break; }

        }

        printf("Case #%d: ", u);

        printf("%d\n", ans);

    }

    return 0;

}

 

你可能感兴趣的:(round)