Cod sursa(job #3332012)

Utilizator cristi_macoveiMacovei Cristian cristi_macovei Data 2 ianuarie 2026 21:50:32
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
// if this gets accepted i'm drinking tonight
#include <vector>
#define use_fast_io (std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);)
#define file_io(s) freopen(((std::string)s + ".in").c_str(), "r", stdin); freopen(((std::string)s + ".out").c_str(), "w", stdout)

#define all(a) a.begin(), a.end()
#define range(a,i,j) a.begin() + (i), a.begin() + (j)

#define aall(a, n) a, a + (n)
#define arange(a,i,j) a + (i), a + (j)

const int NMAX = 2e6 + 8;

#include <iostream>
using namespace std;

int n;
bool prime[NMAX];
// vector<int> divs[NMAX];

void sieve_of_eratosthenes() {
	for (int i = 2; i <= n; ++i) {
		prime[i] = true;
	}

	for (int i = 2; i <= n; ++i) {
		if (!prime[i]) {
			continue;
		}

		// divs[i].push_back(i);
		for (int j = 2 * i; j <= n; j += i) {
			prime[j] = false;
			// divs[j].push_back(i);
		}
	}
}

int main() {
	file_io("ciur");

	cin >> n;

	sieve_of_eratosthenes();

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans += prime[i];
	}

	cout << ans << "\n";


	return 0;
}

// Made in Romania