Cod sursa(job #369801)
Utilizator | Data | 29 noiembrie 2009 16:24:47 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include<fstream.h>
long c,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;
}