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 |
WA得实在没招了,特向大牛们求教!!!(付代码)#include <stdio.h> #include <memory.h> int m,n,total,proper; bool isnotprime[1000005]; int primelist[100000]; void prime() { memset(isnotprime,0,sizeof(isnotprime)); int num; __int64 i,j; isnotprime[0] = isnotprime[1] = 1; num = 0; for(i = 2;i <= 1000000;i++) { if(!isnotprime[i]) { primelist[num++] = i; for(j = i * i;j <= 1000000;j += i) isnotprime[j] = 1; } } primelist[num] = 99999999;//为了work()中能break; } void work() { int i,j; total = proper = 0; for(i = 0;;i++) if(primelist[i] >= m) break; if(primelist[i] == 2) proper = 1;//2为特例 for(j = i;primelist[j] <= n;j++) { if((primelist[j] - 1) % 4 == 0) proper++; } total = j - i; } int main() { int x,y; prime(); while(1) { scanf("%d%d",&m,&n); if(m == -1 && n == -1) break; x = m; y = n; if(m < 0) m = 0; if(n < 0) n = 0; work(); printf("%d %d %d %d\n",x,y,total,proper); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator