Cod sursa(job #2536386)

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

typedef long long int lint;
bool v[2000000];

ifstream fin("ciur.in");
ofstream fout("ciur.out");

int main()
{
    int n, cnt = 0;
    fin>>n;
    for(int i = 1; i <= n; i++)
    {
        v[i] = i;
    }
    for (int i = 2; i * i <= n; i += 2)
    {
        for (int j = i * i; j <= n; j += i)
        {
            v[j] = 1;
        }
        if (i == 2)
            i--;
    }

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

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