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

为什么是错的?

Posted by sunnyw at 2011-07-20 09:37:39 on Problem 3978
#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--;
  }
}

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