Cod sursa(job #2312002)
Utilizator | Data | 3 ianuarie 2019 23:12:34 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n,i,j,nr=0;
int main()
{
fin>>n;
bool frecventa[2000001];
for(i=2;i<=n;i++)
frecventa[i]=1;
for(i=2;i<=sqrt(n);i++)
{
if(frecventa[i]==1)
{
nr++;
for(j=i;i*j<=n;j++)
frecventa[i*j]=0;
}
}
fout<<nr;
}