Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:求数据…数据啊啊……In Reply To:求数据…数据啊啊…… Posted by:zsc08_wangqiang at 2010-04-07 21:29:56 > 什么数据都过啦… > 1 1的情况也考虑了,就是一直WA… 素数筛选法…代码 WA啊… #include<iostream> #include<cmath> using namespace std; const int N = 30001; const int M = 5001; int prime(int n) { bool is[N]; int prm[N]; int i,j,maxp=0,k=0; int s, e = (int)(sqrt(0.0+n)+1); memset(is,1,sizeof(is)); prm[k++] = 2; if(n % 2 == 0) maxp = 2; is[0] = is[1] = 0; for(i=4; i<=n; i+=2) is[i] = 0; for(i=3; i<e; i+=2) { if(is[i]) { prm[k++] = i; if(maxp<i && n % i==0) maxp = i; for(s=i*2, j=i*i; j<n; j+=s) is[j] = 0; } } for(; i<=n; i+=2) { if(is[i]) { prm[k++] = i; if(maxp<i && n%i==0) maxp = i; } } return maxp; } int main() { int n,i,j,maxn; int a[M],b[M]; scanf("%d",&n); for(i=0; i<n; i++) { scanf("%d",&a[i]); b[i] = prime(a[i]); //printf("%d \n",b[i]); } j = 0; maxn = -1; for(i=0; i<n; i++) { if(maxn < b[i]) { maxn = b[i]; j = i; } } printf("%d\n",a[j]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator