Pagini recente » Cod sursa (job #559299) | Cod sursa (job #2942034) | Cod sursa (job #2603836) | Cod sursa (job #2701994) | Cod sursa (job #2638112)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int sieve(int n) {
vector<bool> notPrime(n + 1);
int nrPrimes = 0;
notPrime[0] = notPrime[1] = true;
for (int i = 2; i <= n; i++)
if (!notPrime[i])
for (int j = 2 * i; j <= n; j += i)
notPrime[j] = true;
for (int i = 2; i <= n; i++)
if (!notPrime[i]) nrPrimes++;
return nrPrimes;
}
int main() {
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n;
fin >> n;
fout << sieve(n);
return 0;
}