http://acm.hdu.edu.cn/showproblem.php?pid=2710
按最大质因数排序,输出含有最大质因数的数。
比较简单的问题啦。 =w=
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 20005
int factor[N];
void init(){
int k=floor(sqrt((double)N)+0.5),i,j;
for (i=0;i<N;i++)
factor[i]=1;
for (i=2;i<=k;i++){
if (factor[i]==1)
for (j=2;i*j<=N;j++)
factor[i*j]=i;
}
}
int max(int a,int b){
if (a>=b)
return a;
return b;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("2710in.txt","r",stdin);
#endif
int n,t,fac,m,mt;
init();
while (scanf("%d",&n)!=EOF){
m=0;
mt=0;
while(n--){
scanf("%d",&t);
if (factor[t/factor[t]]==1)
fac=max(factor[t],t/factor[t]);
else fac=factor[t];
if (fac>m){
m=fac;
mt=t;
}
}
printf("%d\n",mt);
}
return 0;
}