Cod sursa(job #2538482)

Utilizator robertbirsanRobert Birsan robertbirsan Data 4 februarie 2020 19:39:43
Problema Ciurul lui Eratosthenes Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <bits/stdc++.h>
#define M 2000000

using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

long long int n, i, j, nr;
int v[M + 5], cnt;

void read()
{
    f >> n;
    f.close();
}

void solve()
{
   for (int i=2; i<=n; i++)
    if (v[i] == 0)
   {
       ++cnt;
       for(j=2*i; j<=n; j+=i)
        v[j] = 1;
   }
   g<<cnt;
   g.close();
}

int main()
{
    read();
    solve();
    return 0;
}