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