Cod sursa(job #2783620)

Utilizator NutaAlexandruNuta Alexandru NutaAlexandru Data 14 octombrie 2021 19:59:09
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include<vector>
using namespace std;
bitset <2000001>c;
int main() {
    freopen("2lan.in", "r", stdin);
    freopen("2lan.out", "w", stdout);
    long long x;
    for(long long i=2;i*i<=x;i++)
    {
        if(!c[i])
        {
            for(long long j=i*i;j<=x;j+=i)
            {
                c[j]=1;
            }
        }
    }
    long long nr=0;
    long long i=2;
    while(i<=x){
        if(c[i]==0)
        {
            nr++;
        }
        i++;
    }
    printf("%lld",nr);
    fclose(stdin);
    fclose(stdout);
	return 0;
}