Cod sursa(job #2696897)
Utilizator | Data | 17 ianuarie 2021 09:57:52 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int main()
{
int n;
fin >> n;
vector<int> v(n + 1);
for(int i = 2; i <= n; i++)
{
v[i] = 1;
}
int nrprime = 0;
for(int i = 2; i <= n; i++)
{
if(v[i] == 1)
{
nrprime++;
for(int j = 2 * i; j <= n; j += i)
{
v[j] = 0;
}
}
}
fout << nrprime;
return 0;
}