poj 1595
比较水的一道题。
//============================================================================ // Name : 1595.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <cstdio> #include <cstring> using namespace std; bool flag[1010]; int num[1010]; int N, C, k; int main() { freopen("a.txt", "r", stdin); for(int i = 2;i <= 1010/2;i++){ if(flag[i] == false){ for(int j = i*2;j <= 1010;j+=i){ flag[j] = true; } } } while(scanf("%d%d", &N, &C)!=EOF){ printf("%d %d:", N, C); k = 0; for(int i = 1;i <= N;i++){ if(flag[i] == false){ num[++k] = i; } } if(k%2 == 0){ if(C*2 <= k){ for(int i = (k-(C*2))/2+1, t = 1;t <= C*2;t++, i++){ printf(" %d", num[i]); } printf("\n"); } else{ for(int i = 1;i <= k;i++){ printf(" %d", num[i]); } printf("\n"); } } else{ if(C*2-1 <= k){ for(int i = (k-(C*2-1))/2+1, t = 1;t <= C*2-1;t++, i++){ printf(" %d", num[i]); } printf("\n"); } else{ for(int i = 1;i <= k;i++){ printf(" %d", num[i]); } printf("\n"); } } printf("\n"); } return 0; }