Cod sursa(job #2033070)

Utilizator ScR4PPJarcau Stefan ScR4PP Data 6 octombrie 2017 08:51:50
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;

bool prop(int x)
{
    int ok = 1;
    if(x < 2 || x > 2 && x % 2 == 0)
        ok = 0;
    else
        for(int d = 3; d * d <= x; d +=2)
            if(x % d == 0)
                ok = 0;
    if(ok == 1)
        return true;
    return false;
}
int main()
{
    ifstream f("ciur.in");
    ofstream g("ciur.out");

    int n, x, nr = 0;
    f>>n;
    for(int i = 2; i < n; i++)
        if(prop(i) == true)
            nr++;
    g<<nr;
    return 0;
}