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

帮忙看一下RTE

Posted by RUNSLOWLY at 2008-11-15 17:14:13 on Problem 3511
#include<iostream>
#include<math.h>
using namespace std;
int prime(int n)
{
	int i;
	if(n<2)
		return 0;
	if(n>=2 && n<4)
		return 1;
	for(i=2;i<=(int)sqrt(n*1.0);i++)
	{
		if(n%i==0)
			return 0;
	}
	return 1;
}
int square(int n)
{
	if(n==2)
		return 1;
	if((n-1)%4==0)
		return 1;
	return 0;
}
int main()
{
	int he,mei,i,u,l,num1,shu1[1000000],num2,shu2[1000000],k;
		cin>>u>>l;
		if(u==l && l==-1)
			return 0;	
		shu1[0]=shu2[0]=0;
		shu1[1]=0;
		shu2[1]=0;
		shu1[2]=1;
		shu2[2]=1;
		num1=1;
		num2=1;
		for(i=3;i<=l;i+=2)
		{
			if(prime(i))
			{
				num1++;
				if(square(i))
					num2++;
			}
			shu1[i]=shu1[i+1]=num1;
			shu2[i]=shu2[i+1]=num2;
		}
		k=l;
			he=mei=0;
			if(prime(l) && prime(u))
			{
				he=1;
				if(square(l) && square(u))
					mei=1;
			}

			if(u<0)
				cout<<u<<' '<<l<<' '<<shu1[l]-shu1[0]<<' '<<shu2[l]-shu2[0]<<endl;
			else
                cout<<u<<' '<<l<<' '<<shu1[l]-shu1[u]+he<<' '<<shu2[l]-shu2[u]+mei<<endl;
		while(1)
		{
	    	cin>>u>>l;
	    	if(u==l && l==-1)
	    		break;
			if(l>k)
			{
				if(k%2==0)
				{
					shu1[k]=shu1[k-1];
					shu2[k]=shu2[k-1];
					k++;
				}
				for(i=k;i<=l;i+=2)
				{
					if(prime(i))
					{
			        	num1++;
			           	if(square(i))
			        		num2++;
					}
		        	shu1[i]=shu1[i+1]=num1;
		        	shu2[i]=shu2[i+1]=num2;
				}
				k=l;
			}
			he=mei=0;
			if(prime(l) && prime(u))
			{
				he=1;
				if(square(l) && square(u))
					mei=1;
			}

			if(u<0)
				cout<<u<<' '<<l<<' '<<shu1[l]-shu1[0]<<' '<<shu2[l]-shu2[0]<<endl;
			else
                cout<<u<<' '<<l<<' '<<shu1[l]-shu1[u]+he<<' '<<shu2[l]-shu2[u]+mei<<endl;
		}
	return 0;
}


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