Cod sursa(job #2780902)
Utilizator | Data | 8 octombrie 2021 09:38:43 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int c[2000001];
int main() {
int n;
fin>>n;
int np=0;
for(int i = 2; i*i <= n; i++) {
if(c[i]==0) {
for(int j = i * i; j <= n; j += i)
c[j] = 1;
}
}
for(int i = 2; i<=n;i++)
if(c[i] == 0)
np++;
fout<<np;
return 0;
}