Cod sursa(job #2969588)

Utilizator SennyUrsu Arsenie Senny Data 23 ianuarie 2023 14:22:45
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 2;
bool ciur[maxn];
int main(){
	freopen("ciur.in", "r", stdin);
	freopen("ciur.out", "w", stdout);
	ciur[0] = ciur[1] = true;
	int rs = 0;
	for (int i = 2; i < maxn; i++){
		if (ciur[i] == false){
			rs+=1;
			for (int j = i * 2; j < maxn; j+=i){
				ciur[j] = true;
			}
		}
	}
	int a, rsp;
	cin >> a;
	for (int i = 0; i < a; i++){
		if (ciur[i] == false){
			rsp+=1;
		}
	}
	cout << rsp;
	return 0;
}