Cod sursa(job #326624)
Utilizator | Data | 25 iunie 2009 18:22:29 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include<fstream.h>
int x[2000001];
int main()
{long j,i,n,nr;
ifstream fin("ciur.in");
fin>>n;
for(i=2;i<=n;i++)
x[i]=1;
for(i=2;i<=n;i++)
if(x[i])
for(j=i+i;j<=n;j+=i)
x[j]=0;
fin.close();
ofstream fout("ciur.out");
nr=0;
for(i=2;i<=n;i++)
if(x[i])
nr++;
fout<<nr;
fout.close();
return 0;
}