Cod sursa(job #1644153)
| Utilizator | Data | 9 martie 2016 21:44:30 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
int n;
vector <bool> erato;
void sieve (){
for(int i=2;i<=sqrt(n)+1;i++){
if(erato.at(i)){
for(int j=pow(i,2);j<=n;j+=i)
erato.at(j)=false;
}
}
}
int all_smaller_than (int i){
if(i==2) return 1;
return erato.at(i)+all_smaller_than(--i);
}
int main()
{
in>>n;
erato.assign(n+1,true);
sieve();
out<<all_smaller_than(n-1);
return 0;
}
