#include<stdio.h> #include<math.h> void prime(int n,int c); int main() { int n,c,y=0; while(scanf("%d %d",&n,&c)==2) { prime(n,c); printf("\n\n"); } return 0; } void prime(int n,int c) { int num[200],lnum=0,i,j,k,l; for(i=1;i<=n;i++) { k=0; for(j=2;j<=sqrt(i);j++) { if(i%j==0) k++; } if(k==0) { num[lnum++]=i; } } if(lnum%2==0) { if(c*2>=lnum) { printf("%d %d:",n,c); for(i=0;i<lnum;i++) { printf(" %d",num[i]); } } else { l=(lnum-c*2)/2; printf("%d %d:",n,c); for(i=l;i<lnum-l;i++) { printf(" %d",num[i]); } } } else { if((c*2-1)>=lnum) { printf("%d %d:",n,c); for(i=0;i<lnum;i++) { printf(" %d",num[i]); } } else { l=(lnum-c*2+1)/2; printf("%d %d:",n,c); for(i=l;i<lnum-l;i++) { printf(" %d",num[i]); } } } }
Sunday, August 17, 2014
uva : 406 - Prime Cuts
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment