Cod sursa(job #1274690)

Utilizator stefan_gheorgheGheorghe Stefan stefan_gheorghe Data 24 noiembrie 2014 08:59:17
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
long long i,j,n;
int 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;
}