Cod sursa(job #569268)
Utilizator | szabo david emanuel david95 | Data | 1 aprilie 2011 11:19:22 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream>
using namespace std;
bool a[10000];
ifstream f("ciur.in");
ofstream h("ciur.out");
int main()
{
int n, i, j, np;
f >> n;
np = 0;
a[1] = 1;
for ( i = 2; i <= n; i++)
if ( a[i] == 0 )
{
np=np+1;
j = 2 * i;
while (j <= n)
{
a[j] = 1;
j = j + i;
}
}
h << np << endl;
f.close();
h.close();
return 0;
}