#include <iostream> #include <cmath> using namespace std; bool prost(int m){ int k = 0; for (int i=2; i<=sqrt(m); i++) if (m % i == 0) k++; return k==0; }
int main(){ int a, b; cin >> a >> b; for (int i=a; i<=b; i++) if (prost(i)) cout << i << " "; return 0; }
Answers & Comments
Verified answer
#include <iostream>#include <cmath>
using namespace std;
bool prost(int m){
int k = 0;
for (int i=2; i<=sqrt(m); i++)
if (m % i == 0) k++;
return k==0;
}
int main(){
int a, b;
cin >> a >> b;
for (int i=a; i<=b; i++)
if (prost(i)) cout << i << " ";
return 0;
}
Пример:
5 20
5 7 11 13 17 19