Cod sursa(job #1389270)
| Utilizator | Data | 16 martie 2015 09:41:31 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.71 kb |
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int prim(long x)
{ int d,ok;
if(x==0||x==1)
return 0;
else
if(x%2==0)
if(x==2)
return 1;
else
return 0;
else
{
d=3; ok=0;
while(d<=sqrt(x))
if(x%d==0)
{ x=d;
ok=1;
}
else
d=d+2;
}
if(ok==0)
return 1;
else
return 0;
}
int main()
{ long n,i,k;
f>>n;
k=0;
for(i=1;i<=n;i+=2)
if(prim(i))
k++;
g<<k;
}
