Cod sursa(job #1274689)

Utilizator stefan_gheorgheGheorghe Stefan stefan_gheorghe Data 24 noiembrie 2014 08:58:17
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int i,j,n,nr;
bool c[100];
int main()
{
    f>>n;
    for (i=2;i<=n;i++)
    {
        c[i]=true;
    }
    for (i=2;i*i<=n;i++)
    {
        if (c[i])
        {
            for (j=2*i;j<=n;j+=i)
            {
                c[j]=false;
            }
        }
    }
    for (i=2;i<=n;i++)
    {
        if (c[i])
        {
            nr++;
        }
    }
    g<<nr;
    return 0;
}