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(附code)??????????

Posted by RUNSLOWLY at 2008-11-22 12:04:33 on Problem 1595 and last updated at 2008-11-23 18:02:31
#include<iostream>
#include<math.h>
#define NUM 1111
using namespace std;
int prime[NUM]={0,1,2,3};
int time[NUM];
int f()
{
	int i,j;
	for(i=0;i<=3;i++)
		time[i]=i;
	time[4]=time[3];
	int n=4,flag=0;
	for(i=5;i<=NUM;i++)
	{
		flag=0;
		for(j=2;j<=(int)sqrt(i*1.0);j++)
			if(i%j==0)
			{
				flag=1;
				break;
			}	
		if(flag==0)
			prime[n++]=i;
		time[i]=n-1;
	}
	return 1;
}
int main()
{
	int n,k,i;
	f();
	while(cin>>n>>k)
	{
		cout<<n<<' '<<k<<": ";
		if(time[n]%2==0)
		{
			if(time[n]<=2*k)
			{				
				for(i=1;i<=time[n];i++)
					cout<<prime[i]<<' ';
				cout<<endl;
			}
			else
			{
				for(i=time[n]/2-k+1;i<=time[n]/2+k;i++)
					cout<<prime[i]<<' ';
				cout<<endl;
			}
		}
		else
		{
			if(time[n]<=2*k-1)
			{
				for(i=1;i<=time[n];i++)
					cout<<prime[i]<<' ';
				cout<<endl;	
			}
			else
			{
				for(i=time[n]/2+1-(2*k-1)/2;i<=time[n]/2+1+(2*k-1)/2;i++)
					cout<<prime[i]<<' ';
				cout<<endl;
			}
		}
		cout<<endl;
	}
	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