Cod sursa(job #894889)
Utilizator | Antohi Bogdan bog29 | Data | 27 februarie 2013 00:52:56 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<fstream>
#define dmax 2000002
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
int main()
{
int n;
in>>n;
in.close();
bool x[dmax];
int nr = 0;
for(int i=2; i <= n; i++)
x[i] = 1;
for(int i=2; i <= n; i++)
if(x[i] == 1)
{
nr++;
for(int j=i; j <= n; j+=i)
x[j] = 0;
}
out<<nr;
out.close();
return 0;
}