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 woainiyanyan at 2009-09-04 16:07:25 on Problem 1595
#include<iostream>
#include<cmath>
using namespace std;
int prime[10000];
short judge(long x)
{
  long i;
  for(i=2;i<=sqrt((double)(x));i++)
  {
	if(x%i==0)
	{
		return 1;
	}
  }
return 0;
}
int main()
{
	long a,c;
	long i;
	while(cin>>a>>c)
	{
		int sum=0; int num=0;
		for(i=1;i<=a;i++)
		{
			if(judge(i)==0)
			{
				prime[num]=i;
				sum++;
				num++;
			}
		}
		if(a==c)
		{
			cout<<a<<" "<<c<<":"<<" ";
			for(i=0;i<num;i++)
			{
				cout<<prime[i]<<" ";
			}
			cout<<endl;
		}
		else
			if(a%2==0)
			{
				cout<<a<<" "<<c<<":"<<" ";
				for(i=(sum-2*c)/2;i<sum/2+c;i++)
				{
					cout<<prime[i]<<" ";
				}
				cout<<endl;
			}
			else
			{
				cout<<a<<" "<<c<<":"<<" ";
				for(i=(sum+1-2*c)/2;i<sum-2*c+1;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