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 |
这个样子竟然会超时?#include <iostream> #include <cstdio> #include <algorithm> #define ll long long using namespace std; int prim[200000]={2,3,5}; int k =3; void is_prim() { int i, j; int flag, step = 2; for(i=7;i<=1000000;i+=step) { step = 6-step; flag = 1; for(j=0;prim[j]*prim[j]<=i;j++) if(i%prim[j] == 0){ flag = 0; break; } if(flag) prim[k++] = i; } } int main() { int L, U; int i, ans1, ans2, j; is_prim(); while(scanf("%d %d",&L,&U),L!=-1||U!=-1){ ans1 = ans2 = 0; for(i=0;L>prim[i];i++); for(j=i;prim[j]<=U;j++) { printf("%d \n",prim[j]); if((prim[j]-1)%4 == 0|| prim[j]==2) ans2++; ans1++; } printf("%d %d %d %d\n",L,U,ans1,ans2); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator