标签:log ons 线性 ble 题目 space mat iostream bbb
http://poj.org/problem?id=3048 (题目链接)
给出n个数,问其中哪个数拥有最大的质因子。
线性筛求素数
。。
// poj3048
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#define MOD 1000000007
#define inf 2147483640
#define LL long long
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
const int maxn=20010;
int n,p[maxn],vis[maxn];
int main() {
	free("bbb");
	scanf("%d",&n);
	for (int i=2;i<=20000;i++) {
		if (!vis[i]) p[++p[0]]=i;
		for (int j=1;j<=p[0] && i*p[j]<=20000;j++) {
			vis[p[j]*i]=1;
			if (i%p[j]==0) break;
		}
	}
	int ans=0,nn=0;
	for (int x,i=1;i<=n;i++) {
		scanf("%d",&x);
		if (x==1 && nn<1) nn=ans=1;
		for (int j=p[0];j && p[j]>nn;j--) if (x%p[j]==0) nn=p[j],ans=x;
	}
	printf("%d",ans);
    return 0;
}
标签:log ons 线性 ble 题目 space mat iostream bbb
原文地址:http://www.cnblogs.com/MashiroSky/p/6067534.html