Cod sursa(job #781265)
| Utilizator | Data | 24 august 2012 00:02:32 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
#define Elemente 1000005
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
unsigned long int n, nr=1, a[Elemente];
void Eratostene(void)
{
unsigned long int i, j;
for(i=1; i+i+1<=n; ++i)
{
if(a[i]==0)
{
nr++;
for(j=i+i+i+1; j+j+1<=n; j+=i+i+1)
a[j]=1;
}
}
}
int main(void)
{
fin>>n;
Eratostene();
fout<<nr;
fin.close();
fout.close();
return 0;
}
