Cod sursa(job #1897744)

Utilizator PuiseIovu Vali Puise Data 1 martie 2017 17:47:59
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<iostream>
#include<fstream>
#include<math.h>
using namespace std;

 ifstream f("ciur.in");
  ofstream g("ciur.out");
    long n,i,j;
    bool  a[200001];
    int k;


int main()
{

    f>>n;
    for(i=2; i<=n; i++)
      {
          if(a[i]==0)
          {k++;
          for(j=i; j<=n; j=j+i)
              a[j]=1;

          }
      }

    f.close();
    g<<k;
    g.close();
  return 0;
}