Cod sursa(job #1731724)

Utilizator AndreiukAndrei C Andreiuk Data 19 iulie 2016 18:15:25
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");

int erathostene (int n)
{
	bool a[n+1];
	int nr,i,j;
	a[0]=1;
	a[1]=1;
	for(i=2;i<=n; ++i)
	 if(a[i]==0) {nr++;
				  for(j=2; j*i<=n; j++) a[i*j]=1;
	              } 
	return nr;
}

int main()
{ int n;
  f>>n;
  g<<erathostene(n);
  return 0;
}