Cod sursa(job #2043713)

Utilizator kywyPApescu tiGEriu kywy Data 20 octombrie 2017 13:55:59
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include<cstdio>
#include<algorithm>
using namespace std;
bool v[2000007];
int main()
{
    FILE* in = fopen("ciur.in", "r"); ///probleme
    FILE* out = fopen("ciur.out", "w");
    v[1] = 1;
    int n, ct = 0;
    fscanf(in, "%d", &n);
    if(n >= 2) ++ct;
    for(int i = 4; i <= n; i += 2) v[i] = 1;
    for(int i = 3; i <= n; i += 2)
    {
        if(v[i] == 0)
        {
            ++ct;
            if(1LL * i * i <= n) for(int j = i * i; j <= n; j += i) v[j] = 1;
        }
    }
    fprintf(out, "%d", ct);
}