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

正如楼下所说,数组要开到1100才能过,附ac代码

Posted by 920394589 at 2017-08-18 13:39:34 on Problem 1595
#include<stdio.h>

const int maxn = 1101;
int p[maxn],cnt;
int n,c;

void getTable(){
	for(int i=2;i*i<maxn;++i){
		if(!p[i]){
			for(int j=i*2;j<maxn;j+=i)p[j]=1;
		}
	}
	cnt=0;
	for(int i=1;i<maxn;++i)if(!p[i])p[cnt++]=i;
}

int main(){
	getTable();
	while(scanf("%d%d",&n,&c)==2){
		printf("%d %d:",n,c);
		int i=0;
		while(p[i]<=n)++i;
		if(i&1)c=c*2-1;
		else c*=2;
		int max_output = c<i?c:i;
		int st=i-max_output>>1;
		int end=st+max_output;
		for(;st<end;++st){
			printf(" %d",p[st]);
		}
		putchar('\n');
		putchar('\n');
	}
	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