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 |
一次ac,不过要16ms,求0ms做法#include <cstdio> #include <cstring> const int N = 50000; bool a[N]; int p[N]; int n=50000; void Prime2() { memset(a, 0, n*sizeof(a[0])); int num = 0, i, j; for(i = 2; i < n; ++i) { if(!(a[i])) p[num++] = i; for(j = 0; (j<num && i*p[j]<n); ++j) { a[i*p[j]] = 1; if(!(i%p[j])) break; } } } int main() { int number; Prime2(); a[0]=true,a[1]=true; while(scanf("%d",&number)!=EOF && number) { int ans=0; for(int i=0;p[i]<number/2+1;++i)if(!a[number-p[i]])++ans; printf("%d\n",ans); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator