Cod sursa(job #326625)
Utilizator | Data | 25 iunie 2009 18:24:36 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include<fstream.h>
char 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]=='1')
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]=='1')
nr++;
fout<<nr;
fout.close();
return 0;
}