Cod sursa(job #1502443)

Utilizator hantescuHantascu Alexandru hantescu Data 14 octombrie 2015 17:35:22
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f ("ciur.in");
ofstream g ("ciur.out");
int n, v[2000005],k = 1;

int main()
{
    int i,j;
    f>>n;
    for(i = 3; i <= n; i = i + 2){
        if(v[i] == 0){
            k++;
            for(j = 3 * i; j <= n; j = j + 2*i){
                v[j] = 1;
            }
        }
    }
    g<< k;
    return 0;
}