Cod sursa(job #369796)
Utilizator | Data | 29 noiembrie 2009 16:21:10 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream.h>
long n,a,d,b,nr;
char v[1000000],gasit;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
f>>n;
nr=1;
d=3;
while(d<=n)
{
a=d;b=d<<1;
while(a<=n){c=a>>1;if(!v[c]){v[c]=1;nr++;}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;
}