Cod sursa(job #2355219)
Utilizator | Data | 25 februarie 2019 21:42:51 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int main()
{
const int LIMIT = 2e6;
bool prim[LIMIT + 5] = {0};
int total = 0;
int x;
fin >>x;
for(int i = 2; i < x; ++i)
{
if(!prim[i])
{
++total;
for(int j = i + i; j < x; j += i)
prim[j] = 1;
}
}
fout << total;
}