Cod sursa(job #1990606)

Utilizator KeitaroAbderus Alastor Keitaro Data 12 iunie 2017 18:39:51
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include<iostream>
#include<stdio.h>
using namespace std;

int eratosthenes(int n) {
	int a[200005];
	int count = 0;
	for (int i = 2; i <= n; i++)
		a[i] = 1;
	for (int i = 2; i <= n; i++)
		if (a[i] == 1)
		{
			count++;
			for (int j = i + i; j <= n; j += i)
				a[j] = 0;
		}
	return count;
}

int main()
{
	int n;
	freopen("ciur.in", "r", stdin);
	freopen("ciur.out", "w", stdout);
	scanf("%d", &n);
	printf("%d", eratosthenes(n));
	return 0;
}