Cod sursa(job #856617)
Utilizator | Data | 16 ianuarie 2013 19:48:41 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int n;
int prim(int x)
{int ok=1,d=2;
while(d<=x/2 && ok)
{
if(x%d==0)
ok=0;
d++;
}
if(ok)
return 1;
else
return 0;
}
int main()
{int j,k=1;
f>>n;
for(j=3;j<=n;j+=2)
if(prim(j))
k++;
g<<k;
f.close();
g.close();
}