Cod sursa(job #2536407)

Utilizator Alexandru_CSMConstantinescu Alexandru Alexandru_CSM Data 1 februarie 2020 21:54:49
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
#include <math.h>
#include <fstream>
using namespace std;

typedef long long int lint;

bool v[2000000];
int n, cnt = 0;

ifstream fin("ciur.in");
ofstream fout("ciur.out");
void rezolvare()
{
    for (int i = 2; i <= n; i += 2)
    {
        if(v[i] != 2)
        {
            v[i] = 1;
        }
    }

    for(int i = 3; i <= sqrt(n); i++)
    {
        for(int j = i*i; j <= n; j++)
        {
            v[j] = 1;
        }
    }
}
int main()
{
    fin>>n;
    rezolvare();

    for(int i = 3; i <= n; i+= 2)
    {
        if(v[i] != 1)
        {
            cnt++;
        }
    }
    fout<<cnt;

    fin.close();
    fout.close();
    return 0;
}