Cod sursa(job #2237602)

Utilizator AlexAboAbogatoaie Alexandru AlexAbo Data 2 septembrie 2018 13:39:51
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

using namespace std;
int i,j,x,cnt;
long long int n;
long long int l = 2000000;
fstream f ("ciur.in");
ofstream g ("ciur.out");
int main() {
f >> n;
if(n >= 2 && n <= l  ) {
bool nr[n]= {false};
for(i = 2;i<=n*0.5;i++) {
    if (!nr[i]) {
        for (j = i*i; j<=n;j+=i) {
            nr[j] = 1;
        }
    }
}

for (x = 1;x<=n;x++) {
    if (nr[x] == 0) {
        cnt++;

    }

}
g << cnt - 1;
}
return 0;
}