#include<iostream>
#include<math.h>
using namespace std;
int is_sushu(int n) {
if (n == 2) {
return 1;
}
else if (n == 1) {
return 0;
}
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int main()
{
int M, N, flag = 0, m_info = 0, n_info = 0, count = 0, i = 1, print_count = 0;
cin >> M >> N;
while (flag == 0) {
if (is_sushu(i) == 1) {
count++;
if (count == M) {
m_info = i;
}
if (count == N) {
n_info = i;
flag = 1;
}
}
i++;
}
for (int j = m_info; j <= n_info; j++) {
if (is_sushu(j) == 1) {
print_count++;
if (print_count % 10 == 0) {
printf("%d\n", j);
}
else {
if (j == n_info) {
printf("%d", j);
}
else {
printf("%d ", j);
}
}
}
}
return 0;
}
这里需要注意的还是一个循环的范围的问题,求素数循环的方根值,不然就会超时。