Cod sursa(job #2247613)

Utilizator Alex_D2019Alexandru Diaconu Codrut Alex_D2019 Data 28 septembrie 2018 20:43:53
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int n,h=1,q,ok=0;
    cin >> n;
    for (int i=3; i<=n; i++)
    {
        q=sqrt(i);
        for (int j=2; j<=q; j++)
        {
            if (i%j==0)
            {
                ok=1;
                break;
            }
        }
        if (ok==0)
            h++;
        ok=0;
    }
    cout << h << endl;
    return 0;
}