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 mailwzy at 2010-03-15 12:17:19 on Problem 1595
#include<iostream>
using namespace std;

int prime[1000];

bool is_prime(int n)
{
	if(n==1||n==2)return 1;
	int i;
	if((n!=2&&n%2==0)||(n!=3&&n%3==0)||(n!=5&&n%5==0)||(n!=7&&n%7==0)||(n!=11&&n%11==0))
		return 0;
	for(i=1;prime[i]*prime[i]<n;i++)
		if(n%prime[i]==0)return 0;
	return 1;
}

int main()
{
	int n,c,k,i,s,time;
	while(cin>>n>>c)
	{
		k=0;
		for(i=1;i<=n;i++)
			if(is_prime(i))prime[k++]=i;
		if(k%2)
			if(k>=2*c-1){s=(k-2*c+1)/2;time=2*c-1;}
			else {s=0;time=k;}
		else
			if(k>=2*c){s=(k-2*c)/2;time=2*c;}
			else {s=0;time=k;}	
		cout<<n<<" "<<c<<":";
		while(time--)
			cout<<" "<<prime[s++];
		cout<<endl<<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