Cod sursa(job #766822)
| Utilizator | Data | 12 iulie 2012 12:10:46 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
#include <iostream>
#include <math.h>
using namespace std;
bool a[2000000];
int rez = 0;
void Sieve (int x)
{
for (int i=2; i<=x; i++)
if (a[i]==false)
{
rez++;
for (int j = 2; j<=x/i; j++)
a[j*i]=true;
}
}
int main ()
{
ifstream afile ("ciur.in");
ofstream bfile ("ciur.out");
int n;
afile>>n;
Sieve(n);
bfile<<rez;
return 0;
}
