Cod sursa(job #987703)
Utilizator | Data | 21 august 2013 13:05:59 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int main ()
{
int N,vp,d,k=0,nr=2;
f>>N;
while(nr<=N)
{
if(nr%2==0&&nr!=2)
vp=0;
else
{
d=3;
vp=1;
while(d<=nr/2&&vp==1)
if(nr%d==0)
vp=0;
else
d=d+2;
}
if(vp==1)
k++;
nr++;
}
g<<k;
g.close();
return 0;
}