Cod sursa(job #1513969)
Utilizator | Data | 30 octombrie 2015 13:24:28 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#include <string.h>
#define nmax 2000001
using namespace std;
bool v[nmax + 1];
int n;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
f >> n;
int nr = 0;
memset(v, 1, sizeof(v));
for (int i = 2; i <= n; i++)
if (v[i] == 1)
{
nr++;
for (int j = i * i; j <= n; j += i) v[j] = 0;
}
g << nr;
return 0;
}