Cod sursa(job #2293586)

Utilizator chiutamarcelChiuta Mihai Marcel chiutamarcel Data 1 decembrie 2018 11:36:00
Problema Ciurul lui Eratosthenes Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <stdio.h>
#include <vector>
using namespace std;



int main() {

	freopen("ciur.in", "r", stdin);
	freopen("ciur.out", "w", stdout);

	const int MAXSIZE = 2000000;
	int n = 0, c = 0;
	char p[MAXSIZE];

	scanf("%d", &n);

	for (int i = 2; i <= n; i++) {
		if(p[i] == 0){
            c++;
            for (int j = i + i; j <= n; j += i) {
                p[j] = 1;
            }
		}
	}

	printf("%d\n", c);

	return 0;
}