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 derness at 2007-07-27 23:34:21 on Problem 3292
#include <iostream>
#include <cmath>
using namespace std;
struct array{
	bool disp;
	unsigned int value;
};
int main(void)
{
	unsigned int H;
	unsigned long i,j,index;
	unsigned int count;
	struct array *a=new struct array[1000002];
	for(i=5;i<1000002;i+=4){
		a[i].value=0;
		a[i].disp=false;
	}
	for(i=5;i<1001;i+=4){
		for(j=5,index=i*j;index<1000002,j<(1000002/i)+1;j+=4)
		{
			index=i*j;
			if(a[i].value==0 && !a[i].disp)
				a[index].value=1;
			else{
				a[index].value=0;
				a[index].disp=true;
			}
		}
	}
	while(1){
		cin>>H;
		if(H ==0)
			break;
		count=0;
		for(i=5;i<=H;i+=4){
			if(a[i].value)
				count++;
		}
		cout<<H<<" "<<count<<endl;
	}
	delete[]a;
	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