Cod sursa(job #2932542)
| Utilizator | Data | 3 noiembrie 2022 09:13:47 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
const int N = 2e6+5;
bool ciur[N];
void sieve(int n)
{
ciur[1]=1;
for(int i=2;i*i<=n;i++)
if(!ciur[i]) for(int j=2;i*j<=n;j++) ciur[i*j]=1;
}
int main()
{
int n; in>>n;
sieve(n);
int nr=0;
for(int i=2;i<=n;i++)
if(!ciur[i]) nr++;
out<<nr;
}
