Cod sursa(job #896535)
| Utilizator | Data | 27 februarie 2013 16:02:33 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
# include <fstream>
using namespace std;
ifstream cein ("ciur.in");
ofstream ceou ("ciur.out");
int n,k,i,y,x,m;
bool a[1001];
int ciur ();
void ceifs ()
{
cein>>n;
}
void ceofs ()
{
ceou<<ciur();
}
int main ()
{
ceifs ();
k = 0;
ceofs ();
}
int ciur ()
{
for (i = 2; i <= n; i++)
a[i] = true;
if (a[i])
for (y = 2; y <= n; y++)
for (m = 2*y; m <= n; m += y)
a[m] = false;
for (x = 2; x <= n; x++)
if (a[x])
k++;
return k;
}
