Cod sursa(job #1548632)
| Utilizator | Data | 11 decembrie 2015 10:41:49 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
#define nmax 2000001
using namespace std;
int n, rez;
bool A[nmax];
int main()
{
ifstream fi("ciur.in");
ofstream fo("ciur.out");
fi >> n;
for (int i = 2; i <= nmax; i++)
if (A[i] == 0)
{
if (i <= n)
rez++;
else
break;
for (int j = 2 * i; j <= nmax; j += i)
A[j] = 1;
}
fo << rez << "\n";
fi.close();
fo.close();
return 0;
}
