Cod sursa(job #369778)
Utilizator | Data | 29 noiembrie 2009 15:50:27 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream.h>
#include<math.h>
long n,a,d,b,nr;
char v[2000001],gasit;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
f>>n;
b=sqrt(n);
nr=1;
d=3;
while(d<=b)
{
a=d;
while(a<=n){v[a]=1;nr++;a+=d;}
gasit=0;a=d+2;
while(!gasit)
{
if(!v[a]){d=a;gasit=1;}
else a+=2;
}
}
g<<nr;
return 0;
}