#include <iostream>
#include <cmath>
using namespace std;
bool prime(long n){
if (n == 1 || n == 0)
return false;
for(long i=2;i<=sqrt(n);i++)
if(n%i==0)
return true;
}
int main() {
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++)
if (prime(i))
cout << i << " ";
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <cmath>
using namespace std;
bool prime(long n){
if (n == 1 || n == 0)
return false;
for(long i=2;i<=sqrt(n);i++)
if(n%i==0)
return false;
return true;
}
int main() {
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++)
if (prime(i))
cout << i << " ";
return 0;
}