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

为什么Memory Limit Exceed?用什么算法?????????

Posted by windbells at 2004-06-16 20:16:39 on Problem 1595
#include<stdio.h>
#include<math.h>
int main()
{
	int n,c,num,i,j;
	while(scanf("%d%d",&n,&c)!=EOF)
	{
		int arry[1001]={0};
		if(n==1)
		{
			printf("%d %d: 1\n\n",n,c);
			continue;
		}
		num=0;
		for(i=2;i<=sqrt(n);i++)
			for(j=i*2;j<=n;j++)
				if((j%i==0)&&(arry[j]==0))
				{
					arry[j]=1;
					num++;
				}
		num=n-num;
		i=0;
		for(j=1;j<=n;j++)
			if(arry[j]==0)
				arry[++i]=j;
		printf("%d %d:",n,c);
		if(c>=num)
			for(i=1;i<=num;i++)
				printf(" %d",arry[i]);
		else if(num%2==0)
			for(i=num/2-c+1;i<=num/2+c;i++)
				printf(" %d",arry[i]);
		else if(num%2==1)
			for(i=num/2-c+2;i<=num/2+c;i++)
				printf(" %d",arry[i]);
		printf("\n\n");
	}
}

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