Cod sursa(job #2644179)
Utilizator | ma cheama alex koda | Data | 23 august 2020 18:23:20 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
bool v[2000001];
int main () {
ifstream fin ("ciur.in");
ofstream fout ("ciur.out");
int n, marker;
fin>>n;
for ( int starter = 2; starter <= n/2; starter++ ) {
marker = starter * 2;
while ( marker <= n ) {
v[marker] = true;
marker += starter;
}
starter += starter % 2;
}
int t = 0;
for ( int i = 2; i <= n; i++ )
t += !v[i];
fout<<t;
return 0;
}