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:sunnyw at 2011-07-20 09:37:39 > #include<stdio.h> > #include<math.h> > main() > { > int a,b,i,j,count,m,k=1000; > while(scanf("%d%d",&a,&b)&&a!=-1&&b!=-1&&k) > { > count=0; > for(i=a;i<=b;i++) > { > m=(int)sqrt(i); > for(j=2;j<=m;j++) > { > if(i%j==0) > { > break; > } > } > if(j>m) > count++; > } > if(a==0) /*当a=0时,加了一次,当a=1时加了一次,所以减2*/ > printf("%d\n",count-2); > else if(a==1) /*a=1时加了一次,所以减,1*/ > printf("%d\n",count-1); > else > printf("%d\n",count); > k--; > } > } a ,b可能为0的,需要考虑,输入-1 1你的就会结束·········· Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator