Cod sursa(job #406115)
Utilizator | Data | 1 martie 2010 10:47:36 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream.h>
#include<math.h>
char v[4000100];
int main()
{
bool gasit;
int nn,t,a,b,d,c,i,n,nr=1;
ifstream f("ciur.in");
ofstream g("ciur.out");
f>>n;
nn=sqrt(n);
d=3;
while(d<=n)
{
nr++;
if(d<=nn)
{
a=d*d;
b=(d<<1);
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;
}