Cod sursa(job #815392)
Utilizator | Data | 16 noiembrie 2012 21:53:52 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
int n,h=1;
bool a[2000002];
int main()
{
int i, j;
ifstream fin("ciur.in");
fin>>n;
fin.close();
for(i = 3; i* i <= n; i++)
if (a[i] == 0) // i este prim
for (j = i * i; j <= n; j = j + 2*i)
a[j] = 1;
for (i = 3; i <= n; i += 2)
if (a[i] == 0) h++;
ofstream fout("ciur.out");
fout<<h<<"\n";
fout.close();
return 0;
}