Cod sursa(job #3216757)
Utilizator | Data | 19 martie 2024 17:28:35 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
bool v[2000001];
//0 = neverificat
//1 = neprim
int ciur(int n){
int i=2;
int k=1;
while(i<=n){
int p=2;
while(i*p<=n){
v[i*p]=true;
p++;
}
i++;
while(v[i]!=false && i<=n)
i++;
if(i<=n)
k++;
}
return k;
}
int main()
{
int n;
f>>n;
g<<ciur(n);
return 0;
}