Cod sursa(job #574423)
Utilizator | Data | 7 aprilie 2011 10:31:53 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
#include <math.h>
using namespace std;
int main()
{
ofstream g ("ciur.out");
ifstream f ("ciur.in");
char p[2000005];
long n,nr=0;
float rad;
f>>n;
f.close();
rad=sqrt(n);
for(int i=2;i<=rad;i++)
{
if(p[i]==0)
{
for(int j=i*i;j<=n;j+=i) p[j]=1;
}
}
for(int i=2;i<=n;i++) if (p[i]==0) nr++;
g<<nr;
g.close();
}