Cod sursa(job #2380749)

Utilizator Maria_cbMaria-Cipriana Burlacu Maria_cb Data 15 martie 2019 14:44:00
Problema Ciurul lui Eratosthenes Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include<bits/stdc++.h>

using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");

bool v[2000001];

int main()
{
    int N,x,i,j,contor=0;
    in>>N;
    for(i=3;i<=N;i+=2)
    {
        for(j=i+i;j<=N;j+=i)
        {
            v[j]=1;
        }
    }
    for(i=2;i<=N;i++)
    {
        if(i>2 && i%2==0)
            v[i]=1;
        if(v[i]==0)
            contor++;
    }
    out<<contor;
    return 0;
}