Cod sursa(job #2232396)
Utilizator | Data | 18 august 2018 22:10:44 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n, m;
bool t[2000002];
int main()
{
fin >> n;
int rad=sqrt(n);
for(int i = 2; i <= rad; ++i)
{
int j = 2;
while (i*j <= n)
{
t[i*j] = 1;
++j;
}
}
int nr = 0;
for(int i = 2; i <= n; ++i)
if( !t[i]) ++nr;
fout << nr;
return 0;
}