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

超级菜鸟,迫求高手,帮忙看看!why Runtime Error(急)

Posted by liweishun2269 at 2007-08-12 11:39:45 on Problem 1595
#include<iostream>
#include<cmath>
using namespace std;
int checkp(int num)
{
	int k,i;
	k=sqrt(num);
	for(i=3;i<=k;i+=2)if(num%i==0)break;
	if(i<=k)return 0;
	return 1;
}
int main()
{
	int prime[11010],n,c,sum,i,she,flag;
	for(i=1;i<=11000;i++)prime[i]=0;
	prime[2]=1;prime[1]=1;
	for(i=3;i<11000;i+=2)if(checkp(i))prime[i]=1;
	while(cin>>n>>c)
	{
		cout<<n<<" "<<c<<": ";
		if(n==1){cout<<1<<endl<<endl;continue;}
		sum=0;
		for(i=1;i<=n;i++)if(prime[i])sum++;
		if(sum%2==0)
		{
			if(2*c>sum)c=sum/2;
			she=sum/2-c;
			flag=0;
			for(i=1;;i++)
			{
				if(flag==she)break;
				if(prime[i])flag++;
			}
			i--;
			flag=0;
			for(i=i+1;;i++)
			{
				if(prime[i])
				{
					cout<<i<<" ";
					flag++;
					if(flag==2*c-1)break;
				}
			}
			for(i=i+1;;i++)if(prime[i]){cout<<i<<endl<<endl;break;}
		}
		else
		{
			if(2*c-1>sum)c=(sum+1)/2;
			she=(sum+1)/2-c;
			if(she<0)she=0;
			flag=0;
			for(i=1;;i++)
			{
				if(flag==she)break;
				if(prime[i])flag++;
			}
			i--;
			flag=0;
			for(i=i+1;;i++)
			{
				if(prime[i])
				{
					cout<<i<<" ";
					flag++;
					if(flag==2*c-2)break;
				}
			}
			for(i=i+1;;i++)if(prime[i]){cout<<i<<endl<<endl;break;}
		}
	}
	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