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

Re:请问用时很少的同志们是不是素数的判断有什么技巧?指点一下啊!会非常感激的!!!

Posted by xfxyjwf at 2005-03-14 19:23:03 on Problem 2262
In Reply To:请问用时很少的同志们是不是素数的判断有什么技巧?指点一下啊!会非常感激的!!! Posted by:fjnu0205046 at 2005-03-14 19:00:24
#include <stdio.h>
#include <memory.h>
bool odd[1000001];
int main()
{
	int i, j;
	int x;
	memset(odd, true, sizeof(odd));
	for(i = 2; i <= 500000; i++)
	{
		if(odd[i])
		{
			for(j = 2; j < 1000000/i; j++)
			{
				odd[i + j * i] = false;
			}
		}
	}
	scanf("%d", &x);
	while(x > 0)
	{
		for(i = 3; i <= x/2; i += 2)
		{
			if(odd[i] && odd[x-i])
			{
				break;
			}
		}
		printf("%d = %d + %d\n", x, i, x-i);
		scanf("%d", &x);
	}
	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