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 244549721 at 2011-07-21 17:21:41 on Problem 3978
#include<stdio.h>
#include<math.h>
int find (int x);
main()
{
	int a,b,i,k;
	while(scanf("%d %d",&a,&b)!=EOF&&a,b!=-1)
	{
		k=0;
		for(i=a;i<=b;i++)
		{
			if(find(i)==1) k++;
		}
		printf("%d\n",k);
	}
}
int find (int x)
{
	int i,flag=1;
	if(x<2) 
	{
		flag=0;
	}
	else if(x==2||x==3) flag=1;
	else
	{
		for(i=2;i<=sqrt(x);i++)
		{
			if(x%i==0)
			{
				flag=0;
				break;
			}
			
		}
	}
	
	return flag;
}

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