Cod sursa(job #2640440)
| Utilizator | Data | 6 august 2020 14:28:38 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nmax = 2000005;
int vect[nmax];
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int main()
{
int n;
fin >> n;
vect[0] = 0;
vect[1] = 1;
for (int i = 2; i <= n; i++)
{
if(vect[i] == 0)
{
for (int j = i + i; j <= n; j += i)
vect[j] = 1;
}
}
int cnt = 0;
for (int i = 2; i <= n; i++)
if(!vect[i])
cnt++;
fout << cnt;
}
