Cod sursa(job #1646846)
Utilizator | Data | 10 martie 2016 17:57:51 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
bool V[2000005];
int n;
int eratostene(int x){
int r=0;
V[1]=1;
for(int i=2;i<=x;i++){
if(!V[i]){
r++;
if(i*i>0&&i*i<=x)for(int j=i*i;j<=x;j+=i)
V[j]=1;
}
}
return r;
}
int main(){
in>>n;
out<<eratostene(n);
return 0;
}