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

请玩POJ的高手看看,我的代码为什么TLE,而且感觉这个题有点问题啊

Posted by num9332 at 2010-08-21 15:26:14 on Problem 2262
有人说不可能出现猜想错误的情况,但是题目是说任意一个大于6的数都能分解成两个奇质数,15怎么分解成两个奇质数?那么猜想不就错误了?还有人贴AC的代码,我拿去验证后发现他的程序把15分解成3和12,感觉很奇怪。请大家看看我的代码是什么问题,谢谢了!
#include <stdio.h>
#include <math.h>
int prime[1000001];
int main()
{
	int i,j,k,m,b;
	for(i=2;i<1000001;i++)
	{
		k=sqrt(i);
		for(j=2;j<=k;j++)
		{
			if(i%j==0)
				break;
		}
		if(j>k)
			prime[i]=1;
		else
			prime[i]=0;
	}
	while(1)
	{
		scanf("%d",&m);
		if(m==0)
			break;
		for(i=3;i<=m/2;i++)
		{
			b=m-i;
			if(prime[i]==1&&prime[b]==1)
			{
				printf("%d=%d+%d\n",m,i,b);
				break;
				
			}
		}
		if(i>m/2)
		{
			printf("Goldbach's conjecture is wrong.\n");
		}
	}
	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