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

时间:2021-09-08 15:27:21
#include<stdio.h>
#include<string.h>
#include<math.h>
int flag[];
int a[];
int main()
{
int sb;
scanf("%d", &sb);
int u;
for (u = ; u <= sb; u++)
{
int n, i;
int maxn = -;
scanf("%d", &n);
memset(flag, , sizeof(flag));
for (i = ; i <= n; i++)
{
scanf("%d", &a[i]);
if (a[i] >= maxn) maxn = a[i];
}
for (i = ; i <= n; i++)
{
int j;
for (j = ; j *j <= a[i]; j++)
{
if (a[i] % j == && j*j < a[i]) flag[j]++, flag[a[i] / j]++;
else if (a[i] % j == && j*j == a[i]) flag[j]++;
}
}
int ans;
for (i = maxn; i >= ; i--)
{
if (flag[i] >= ) { ans = i; break; }
}
printf("Case #%d: ", u);
printf("%d\n", ans);
}
return ;
}