Cod sursa(job #3236856)
| Utilizator | Data | 3 iulie 2024 10:08:16 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int nmax = 2e6+10;
vector<short int> eratostene(nmax,0);
int n;
int main(){
fin >> n;
int ans = 0;
eratostene[1] = eratostene[0] = 1;
for(int i = 2; i <=n; i++){
if(!eratostene[i]){
ans++;
for(int j = i*2; j <=n; j += i){
eratostene[j] = 1;
}
}
};
fout << ans;
return 0;
}
