Cod sursa(job #568423)
| Utilizator | Data | 31 martie 2011 10:30:27 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream.h>
#include<cmath>
using namespace std;
int main()
{long int N, d, c, OK, i;
ifstream f("ciur.in");
ofstream h("ciur.out");
f>>N;
if (N<3)
c=1;
else
if (N<5)
c=2;
else
if (N<7)
c=3;
else
if (N>=7)
{c=3;
d=7;
while (d<=N)
{OK=1;
i=3;
do
{if (d%i==0)
OK=0;
i=i+2;
}
while ((i<=int(sqrt((double)d)))&&(OK==1));
if (OK==1)
c=c+1;
d=d+2;
}
}
h<<c<<endl;
f.close();
h.close();
return 0;
}
