Untitled
unknown
plain_text
a year ago
570 B
9
Indexable
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int main() {
int a, b;
cin >> a >> b;
if (a <= 2 && b >= 2) cout << 2 << " ";
if (a % 2 == 0) a++;
for (int i = a; i <= b; i += 2) {
if (isPrime(i)) cout << i << " ";
}
return 0;
}Editor is loading...
Leave a Comment