Cod sursa(job #2076537)

Utilizator severutBogdan Sever-Cristian severut Data 26 noiembrie 2017 18:58:09
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <math.h>

using namespace std;

ifstream fin ("ciur.in");
ofstream fout ("ciur.out");

int main()
{
    int n,x,contor,ok,d;
    fin>>n;
    ok=0;
    contor=1;
    for (int i=2;i<=n;i++)
    {
        if (i%2==1)
        {
            x=sqrt(i);
            ok=0;
            d=2;
            while (d<=x&&ok==0)
            {
                if (i%d==0)
                    ok=1;
                d++;
            }
            if (ok!=1)
                contor++;
        }
    }
    fout<<contor;
    return 0;
}