Cod sursa(job #3284468)

Utilizator emavalvema valvoi emavalv Data 11 martie 2025 17:38:12
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>

using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
char v[2000001];
int main()
{
    long long n, cnt=0;
    in>>n;
    for(int i=0; i<n; i++)
        v[i]='0';
        v[0]=1;
        v[1]=1;
    int d=2;
    while(d*d<=n){
        if(v[d]=='0'){
            for(int j=2; j<=n/d; j++){
                v[j*d]='1';
            }
        }
        d++;
    }

    for(int i=0; i<n; i++){
        if(v[i]=='0')
            cnt++;
    }
    out<<cnt;
    return 0;
}