[讨论]收集这题的各种方法~!
输入整数m,k.求m最近的k个素数,每行输出5个~~~~!(输出的素数都比m大)
[CODE]#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int ival){
if (ival == 1)
return false;
if (ival == 2 || ival ==3)
return true;
for (int i = 2;i <= sqrt(ival);++i)
if(ival % i == 0)
return false;
return true;
}
void findPrime(int m,int k){
int count = 0;
while (count != k){
if (isPrime(m)){
++count;
cout << m << (count % 5 != 0 ? " " : "\n");
}
++m;
}
}
int main(){
int m,k;
cin >> m >> k;
findPrime(m,k);
cout << endl;
system("pause");
}[/CODE]
我想关键就是判断素数这个算法有讨论的价值!
期待楼下!