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 |
为什么是错的,如果把P=0加在while函数里面就对了?#include <stdio.h> #include <math.h> int prime(int x) { int i; if(x<=1) return 0; else if(x==2||x==3) return 1; else { for(i=2;i<=sqrt(x);i++) { if(x%i==0) { return 0; break; } } return 1; } } int main() { int a,b,i,p=0; while(scanf("%d%d",&a,&b)!=EOF) { if((a==-1)&&(b==-1)) return 0; for(i=a;i<=b;i++) { if(prime(i)==1) p++; } printf("%d\n",p); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator