Cod sursa(job #3353098)
| Utilizator | Data | 4 mai 2026 18:52:34 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 70 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("ciur.in");
ofstream fout ("ciur.out");
#define nmax 2000005
int v[nmax];
void ciur(int n){
v[0] = v[1] = 1;
for(int i = 2; i <= sqrt(n); i++){
if(v[i] == 0){
for(int j = 2; j <= n / i; j++){
v[i * j] = 1;
}
}
}
}
int ans;
int main()
{
int n;
fin >> n;
ciur(n);
for(int i = 2; i <= n; i++){
if(!v[i])
ans++;
}
fout << ans;
return 0;
}
