Cod sursa(job #2705299)
| Utilizator | Data | 12 februarie 2021 12:55:43 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 70 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n, k, v[2000001];
int main(){
fin >> n;
for(int i = 2; i <= n; i++)
v[i] = i;
for(int i = 2; i * i <= n; i++){
if(v[i] != -1){
for(int j = 2 * i; j <= n; j+=i){
v[j] = -1;
}
}
}
for(int i = 2; i <= n; i++)
if(v[i] != -1) k++;
fout << k;
return 0;
}
