Cod sursa(job #2237601)

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

using namespace std;
int i,j,x,cnt;
long long int n;
fstream f ("ciur.in");
ofstream g ("ciur.out");
int main() {
if(n >= 2 && n <= 2000000  ) {
f >> n;
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;
}