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 |
为什么Memory Limit Exceed?用什么算法?????????#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator