Untitled
unknown
plain_text
a year ago
406 B
5
Indexable
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int isPrime(int n) {
if (n < 2) return 0;
else if (n == 2 || n == 3) return 1;
else{
for (int _ = 2; _ <= sqrt(n); ++_) {
if (n % _ == 0) return 0;
}
return 1;
}
}
int main()
{
int n;
cin >> n;
for (int _ = 2; _ <= n; ++_) {
if (isPrime(_) == 1) {
cout << _ << '\n';
}
}
return 0;
}Editor is loading...
Leave a Comment