#include<iostream>#include<string>#include<vector> #include<math.h>usingnamespacestd;
intjudge(int n){
if (n < 2)
return0;//非素数for (int i = 2; i*i <= n; i++) {
if (n%i == 0)
return0;//非素数
}
return1;
}
intmain(){
int m, n;
int count = 0; //记录素数的个数vector<int> res;
cin >> m >> n;
int i = 0;
while (count < n) {
i++; //记录当前要判断的的数if (judge(i) == 1) { //i是素数
count++; //记录当前素数的个数if (count >= m)
res.push_back(i);
}
}
count = 0;
for (int i = 0; i < res.size(); i++) {
count++;
if (i < res.size() - 1 && count < 10)
cout << res[i] << " ";
else
{
cout << res[i] << endl;
count = 0;
}
}
return0;
}
python3代码
mport math
defjudge(n):if(n< 2):
return0
max = int(math.sqrt(n))
for i in range(2,max+1):
if(n%i==0):
return0return1defmain():
s = input().split()
num = list(map(int,s))
res = []
i = 2
count = 0# 计算素数的个数while(count < num[1]):
if(judge(i) == 1):
count += 1if(count >= num[0]):
res.append(i)
i += 1
count = 0for i in range(res.__len__()):
count+=1if(count < 10and i != res.__len__() -1):
print(res[i],end=' ')
else:
print(res[i])
count = 0
main()