# 题目

5 27

11 13 17 19 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89
97 101 103

# 代码

## C++解法

```#include <cstring>
#include <iostream>
using namespace std;

const int maxn = 110005;

int prime[maxn];
bool isPrime[maxn];
int pos;

void listPrime(int maxNum) {
memset(isPrime, true, sizeof(isPrime));
isPrime[0] = isPrime[1] = false;
pos = 0;
for (int i = 2; i <= maxNum; ++i) {
if (isPrime[i])
prime[pos++] = i;
for (int j = 0; j < pos && i * prime[j] <= maxNum; ++j) {
isPrime[i * prime[j]] = false;
if (!(i % prime[j]))
break;
}
}
}

int ans[maxn];
int main() {
cin.tie(0);
cin.sync_with_stdio(false);

int n, m;
cin >> n >> m;
listPrime(110000);

bool isFirst = true;
int cnt = 0;
for (int i = n; i <= m; ++i) {
if (cnt == 10) {
cout << endl;
cnt = 0;
isFirst = true;
}
if (isFirst)
isFirst = false;
else
cout << " ";
cnt++;
cout << prime[i - 1];
}
cout << endl;
return 0;
}
```

## Python解法

```def listPrime(MAX):
isPrime = [True for i in range(MAX + 1)]
isPrime[0] = isPrime[1] = False
prime = []
for i in range(2, MAX + 1):
if isPrime[i]:
prime.append(i)
for j in range(0, len(prime)):
if i * prime[j] > MAX:
break
isPrime[i * prime[j]] = False
if not (i % prime[j]):
break
return prime

prime = listPrime(110000)
(n, m) = [int(i)for i in input().split(" ")]

isFirst = True
cnt = 0
for i in range(n, m + 1):
if cnt == 10:
print("\n", end="")
cnt = 0
isFirst = True
if isFirst:
isFirst = False
else:
print(" ", end="")
cnt += 1
print(prime[i - 1], end="")
print("\n", end="")

```

## Java解法

```import java.lang.reflect.Array;
import java.util.*;

class Main {

public static final int maxn = 110005;
public static int[] prime = new int[maxn];
public static boolean[] isPrime = new boolean[maxn];
public static int pos;

public static void listPrime(int maxNum) {
Arrays.fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
pos = 0;

for (int i = 2; i <= maxNum; ++i) {
if (isPrime[i])
prime[pos++] = i;
for (int j = 0; j < pos && i * prime[j] <= maxNum; ++j) {
isPrime[i * prime[j]] = false;
if (i % prime[j] == 0)
break;
}
}
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();

listPrime(110000);
int cnt = 0;
boolean isFirst = true;
for (int i = n; i <= m; ++i) {
if (cnt == 10) {
cnt = 0;
System.out.print("\n");
isFirst = true;
}
if (isFirst)
isFirst = false;
else
System.out.print(" ");
cnt++;
System.out.print(prime[i-1]);
}
System.out.print("\n");
in.close();
}
}
```