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