Cod sursa(job #942134)
| Utilizator | Data | 20 aprilie 2013 22:58:25 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include<fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int n;
bool v[2000000];
void Eratostene()
{
int i,j;
for(i=2;i<=n;i++)
{
if(v[i]==0)
{
for(j=i+i;j<=n;j+=i)
v[j]=1;
}
}
}
void read_number_and_process()
{
f>>n;
Eratostene();
int i,counter=0;
for(i=2;i<=n;i++)
{
if(v[i]==0)
counter++;
}
g<<counter<<"\n";
}
int main()
{
read_number_and_process();
}
