Cod sursa(job #2536403)

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

typedef long long int lint;

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

ifstream fin("ciur.in");
ofstream fout("ciur.out");
void rezolvare()
{
    for(int i = 1; i <= n; i++)
    {
        v[i] = i;
    }
    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 = 1; i <= n; i++)
    {
        if(v[i] != 1)
        {
            cnt++;
        }
    }
    fout<<cnt;

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