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 yufuwan1 at 2008-06-12 12:02:55 on Problem 3006
#include<stdio.h>
#include<math.h>


int main()
{
	long int m,k,i;
	long int a[1000000]={0,0,1,0};

	for(m=3;m<1000000;m=m+2)
	{
		k=sqrt(m);
		for(i=2;i<=k;i++)
			if(m%i==0)
				break;
		if(i>=k+1)
             a[m]=1;
	}

	while(1)
	{
		long int c,d,num;
		long int count=0;
		long int re;
		scanf("%ld%ld%ld",&c,&d,&num);
		if(c==0&&d==0&&num==0)
			break;
		for(re=c;count<num;re+=d)
		{
			if(a[re]==1)
			{
				count+=1;
			}
		}
		printf("%ld\n",re-d);
	}

	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