Cod sursa(job #1150483)
Utilizator | Data | 23 martie 2014 09:31:49 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream>
using namespace std;
#define max 2000001
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
int n,i,j,k=0; bool ciur[max];
f>>n; f.close();
for(i=2;i<=max;i++)
{
if(!ciur[i]&&i<=n)
{for(j=2;i*j<=max;j++) ciur[i*j]=true; k++;}
else if(i>n) break;
}
g<<k<<'\n'; g.close();
return 0;
}