hdu 1319
水题,打素数表即可,都用不着筛法。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXI = 200;
const int MAXV = 1100;
int prime[MAXI], I;
int facnum[MAXV];
void init() {
I = 0;
memset(prime, 0, sizeof(prime));
prime[I++] = 1;
prime[I++] = 2;
int sqr, j;
for (int i = 3; i < MAXV; i++) {
sqr = (int) sqrt(i);
for (j = 2; j <= sqr; j++) {
if (i % j == 0) {
break;
}
}
if (j > sqr) {
prime[I++] = i;
}
}
memset(facnum, 0, sizeof(facnum));
j = 0;
for (int i = 1; i < MAXV; i++) {
if (i == prime[j]) {
j++;
}
facnum[i] = j;
}
}
void myprint(int i, int j) {
for (; i < j; i++) {
printf(" %d", prime[i]);
}
putchar('\n');
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
init();
int N, C, num, s, e;
while (scanf("%d%d", &N, &C) == 2) {
printf("%d %d:", N, C);
num = 2 * C;
if (facnum[N] % 2 == 1) {
num--;
}
s = 0;
e = facnum[N];
if (num < facnum[N]) {
s = (facnum[N] - num) / 2;
e = facnum[N] - s;
}
myprint(s, e);
putchar('\n');
}
return 0;
}