Cod sursa(job #815378)
Utilizator | Data | 16 noiembrie 2012 21:45:23 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
int a[2000000], n,h=1;
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;
}