Cod sursa(job #1357710)
| Utilizator | Data | 24 februarie 2015 02:10:08 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
int n,k;
f>>n;
vector <bool> values (n+1,true);
for (int i = 2; i <= n; i++){
k = i;
for (int j = 2; j*k <= n; j++)
values[j*k] = false;
}
int contor = 0;
for (int i = 2; i <= n; i++)
if (values[i])
contor++;
g<<contor;
g.close();
return 0;
}