Cod sursa(job #2513213)

Utilizator ionuttiplea2001Tiplea Ionut ionuttiplea2001 Data 22 decembrie 2019 15:55:03
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <iostream>
#include <fstream>
#define Nmax 2000001
using namespace std;
ifstream fi("ciur.in");
ofstream fo("ciur.out");
bool v[Nmax];
int main()
{
    int n;
    fi >> n;
    int k = 0;
    for(int i = 1; i <= n; i ++)
       {
           if ( (i&1) == 1) v[i] = 1;
       }
       if( n >= 2) k = 1;
    v[2] = 1;
    for(int i = 3 ; i < n; i += 2)
    {
       if( v[i] == 1)
       {
           k ++;
           for(int j = 2*i; j <= n; j += i)
        {
            v[j] = 0;
        }
       }
    }
    fo<< k;
    fi.close();
    fo.close();
    return 0;
}