Cod sursa(job #2716883)
| Utilizator | Data | 5 martie 2021 20:45:23 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
vector <bool> vis;
int n, nr;
inline void init() {
vis = vector <bool> (n + 1);
}
void ciur() {
vis[0] = 1;
vis[1] = 1;
for(int i = 2; i * i <= n; ++i)
if(!vis[i])
for(int j = 2; j <= n / i; ++j)
vis[i * j] = 1;
}
int main()
{
f >> n;
init();
ciur();
for(int i = 1; i <= n; ++i)
if(!vis[i])
++nr;
g << nr;
}
