Cod sursa(job #2504588)
| Utilizator | Data | 5 decembrie 2019 11:32:06 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream f ("ciur.in");
ofstream g ("ciur.out");
int main()
{
int n,i,ok,x,contor,d;
f >>n;
contor=0;
for (i=1;i<=n;i++)
{
x=i;
if (x<2)
{
ok=0;
}
else
{
ok=1;
d=2;
while (d<=sqrt(x) and ok==1)
{
if (x%d==0)
{
ok=0;
}
else
{
d++;
}
}
}
if (ok==1)
{
contor++;
}
}
g <<contor;
return 0;
}
