Cod sursa(job #2237586)
Utilizator | Data | 2 septembrie 2018 13:22:29 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <bits/stdc++.h>
using namespace std;
int n,i,j,x,cnt;
fstream f ("ciur.in");
ofstream g ("ciur.out");
int main() {
f >> n;
bool nr[n]= {false};
for(i = 2;i<=sqrt(n);i++) {
if (!nr[i]) {
for (j = i*i; j<=n;j+=i) {
nr[j] = 1;
}
}
}
for (x = 1;x<=n;x++) {
if (nr[x] == 0) {
cnt++;
}
}
g << cnt - 1;
}