#include <iostream>
using namespace std;
int main()
{
int m, n;
cin >> m >> n;
int prime[10000];
prime[0] = 2;
int cnt = 1;
for (int i = 3; cnt < n; i++) //注意循环条件不一定仍针对i
{
int flag = 1;
for (int j = 0; j < cnt; j++)
{
if (i % prime[j] == 0)
{
flag = 0;
break;
}
}
if (flag == 0)
continue;
else
prime[cnt++] = i;
}
int num = 1;
for (int i = m-1; i < cnt; i++)
{
if(num % 10 != 0 && i != cnt-1)
cout << prime[i] << " ";
else if (num % 10 == 0 && i != cnt - 1)
{
cout << prime[i] << endl;
}
else
cout << prime[i];
num++;
}
system("pause");
return 0;
}
c++版查指定位置的素数
最新推荐文章于 2023-01-15 11:47:12 发布