Cod sursa(job #664809)
Utilizator | Data | 20 ianuarie 2012 20:44:39 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include<fstream>
using namespace std;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
long n,i,j,k=1;
f>>n;
bool v[n+1];
for(i=2;i<=n;i++)v[i]=0;
for(i=4;i<=n;i=i+2)v[i]=1;
for(i=3;i<=n;i=i+2)if(v[i]==0){k++;for(j=3*i;j<=n;j=j+i)v[j]=1;}
g<<k;
f.close();
g.close();
return 0;
}