Cod sursa(job #444933)

Utilizator wamfeverDobos Ionut wamfever Data 22 aprilie 2010 09:39:34
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.31 kb
#include<fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");

int n, i, no;
char p[2000000]; 

void sterge(int k)
{ for(int j=k; j<=n; j+=k)
  p[j]='x';
}

int main()
{
    fin>>n;
    for(i=2;i<=n;i++) if( p[i] == 'x' ) ++no, sterge(i);
    fout<<no;
    return 0;
}