Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:为什么是错的?

Posted by 1008061011 at 2011-07-20 10:13:15 on Problem 3978
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator