Cod sursa(job #2046777)
Utilizator | Data | 24 octombrie 2017 09:19:11 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int N,i,j,nr;
bool prim[1010];
int main()
{
f>>N;
for(i=2; i<=N; i++) prim[i]=true;
for(i=2; i*i<=N; i++)
{
if(prim[i]==true)
{
for(j=2*i; j<=N; j+=i) prim[j]=false;
}
}
for(i=2; i<=N; i++) {
if(prim[i]==true) nr++;
}
g<<nr;
return 0;
}