直接分解出因子,统计一下就好了
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50010;
map<int,int> res;
int main()
{
int n,num;
scanf("%d",&n);
while(n--)
{
scanf("%d",&num);
for(int i = 1; i*i <= num; ++i)
{
if(num%i == 0)
{
if(i*i == num)
res[i]++;
else
{
res[i]++;
res[num/i]++;
}
}
}
}
for(map<int,int>::reverse_iterator it = res.rbegin(); it != res.rend(); ++it)
{
if(it->second >= 2)
{
printf("%d\n",it->first);
return 0;
}
}
return 0;
}