一道暴力水题
一开始总RE没考虑因子的大小。。。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int tt[50010];
int tt1[1000005];
int max(int a, int b)
{
if (a > b)
return a;
else
return b;
}
int main()
{
int n;
while (cin >> n)
{
for (int i = 0; i < n; i++)
{
scanf("%d", &tt[i]);
}
memset(tt1, 0, sizeof(tt1));
for (int i = 0; i < n; i++)
{
for (int j = 1; j <=(int)sqrt(tt[i]); j++)
{
if (tt[i] % j == 0)
{
if(j*j!=tt[i])
{
tt1[j]++;
tt1[tt[i]/j]++;
}
else
tt1[j]++;
}
}
}
int i;
for (i =1000000; i >=0; i--)
{
if (tt1[i] == 2)
{
cout << i << endl;
break;
}
}
if(i==-1)
cout<<"1"<<endl;
}
return 0;
}