Cod sursa(job #248098)
Utilizator | Data | 24 ianuarie 2009 21:11:13 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream.h>
#include <math.h>
#include <fstream.h>
fstream f("ciur.in",ios::in);
fstream g("ciur.out",ios::out);
int main ()
{
long i,n,d,ok,k;
f>>n;
k=0;
for (i=1;i<=n;i++) {
ok=1;
if (i!=2 && i%2==0) ok=0;
else {
d=3;
while (d<=sqrt(n) && ok==1) {
if (i%d==0) ok=0;
else {
d=d+2;
}
}
}
if (ok==1) k++;
}
g<<k;
return 0;
}