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 godofwa2 at 2012-07-21 19:14:46 on Problem 3292
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

int h[1000010];

int main()
{
	int i,j;
	for (i=5;i<1000;i+=4)
	{
		if (h[i]==0)
		{
			for (j=i;i*j<1000002;j+=4)
			{
				h[i*j]=h[i]+h[j]+1;
			}
			//cout<<i<<endl;
		}
	}//筛出来等于1的都是“素数”,0或者其他不是1的不是

	for (i=25;i<1000002;i++)
	{
		h[i]=(h[i]==1)+h[i-1];
	}//统计

	while(scanf("%d",&i) && i)
	{
		printf("%d %d\n",i,h[i]);
	}
	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