Cod sursa(job #2033073)
Utilizator | Data | 6 octombrie 2017 08:56:19 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
bool prop(int x)
{
int ok=1;
if(x<2 || (x>2 && x%2==0))
ok=0;
else
{
int d=3;
while(d<x)
{
if(x%d==0)
ok=0;
d+=2;
}
}
if(ok==1)
return true;
return false;
}
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
int n,nr=0,x;
f>>n;
for(int i=2;i<n;i++)
if(prop(i)==true)
nr++;
g<<nr;
return 0;
}