Cod sursa(job #2858971)
Utilizator | Data | 28 februarie 2022 18:08:05 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream fin ("ciur.in");
ofstream fout ("ciur.out");
int n;
int prim[2000005], ans;
int main()
{
fin>>n;
for(int i=2; i<=n; i++)
prim[i]=1;
for(int i=2; i<=n; i++)
if(prim[i])
{
ans++;
for(int j=2*i; j<=n; j+=i)
prim[j]=0;
}
fout<<ans;
return 0;
}