Cod sursa(job #916120)
| Utilizator | Data | 15 martie 2013 20:31:01 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
bool Prime[2000001];
int n, count;
void Read();
void Erathostenes();
int main()
{
Read();
Erathostenes();
fin.close();
fout.close();
return 0;
}
void Read()
{
fin >> n;
}
void Erathostenes()
{
for( int i = 2; i <= n; i++ )
{
Prime[i] = true;
}
for( int i = 2; i <= n; i++ )
{
if(Prime[i] == true)
{
count++;
for( int j = 2 * i; j <= n; j += i )
Prime[j] = false;
}
}
fout << count;
}
