Mai intai trebuie sa te autentifici.

Cod sursa(job #2731891)

Utilizator Robys01Robert Sorete Robys01 Data 28 martie 2021 14:56:04
Problema Ciurul lui Eratosthenes Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.38 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 2 * 1e6 + 1;
int a[NMAX];

int main()
{
    int n, nr = 1;
    fin>>n;
    
    for(int i = 3; i <= n; i += 2){
        if(!a[i]){
            nr++;
            for(int j = i + i; j <= n; j += i)
                a[j] = 1;
        }
    }
    fout<<nr;
    return 0;
}