Cod sursa(job #1002207)
| Utilizator | Data | 27 septembrie 2013 00:26:54 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include<fstream>
#include<malloc.h>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
#define NMAX 2000008
int n = 1,nr = 1;
char a[NMAX];
void eratosthenes()
{
for(int i = 2; i <= n; i+=2)
a[i] = 1;
for(int i = 3; i <= n; i += 2)
{
if(!a[i])
{
++nr;
for(int j = i + i; j <= n; j += i)
a[j] = 1;
}
}
}
int main()
{
f>>n;
eratosthenes();
g<<nr << '\n';
g.close();
return 0;
}