Cod sursa(job #1136836)
Utilizator | Data | 9 martie 2014 11:19:30 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream is ("ciur.in");
ofstream os ("ciur.out");
int n, cnt;
bool P[2000002];
int main()
{
is >> n;
P[1] = 1;
for (int i = 2; i <= n; ++i)
if (P[i] == 0)
{
cnt++;
for (int j = i+i; j <= n; j+=i)
P[j] = 1;
}
os << cnt << '\n';
is.close();
os.close();
return 0;
}