Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
正如楼下所说,数组要开到1100才能过,附ac代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator