Cod sursa(job #1500719)

Utilizator dazxAndrei dazx Data 12 octombrie 2015 16:52:58
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

const int NMax = 2e6 + 5;






            /*
             *   _ _ _ _ _ _ _
             *  |             |
             *  |             |   __
             *  |         _ _ |  / _|
             *  |        |    |  | |
             *  |_ _ _ _ |    |_ | | _ _ _ _ _ _
             *  |        |    |                 |
             *  |        |_ _ |                 |
             *  |       /     \      _ _        |
             *  |_ _ _ /       \_ _ /   \_ _ _ _|
             *         |       |   |     |
             *          \ _ _ /     \ _ /
             */


int k;
int Prime[NMax];
int viz[NMax];

void tractor(int n){

    k = 1;
    for(int i = 3; i <= n; i = i + 2){
    if(viz[i] == 0){
        k++;
        Prime[k] = i;
        for(int j = 3 * i; j <= n; j = j + (2*i)){
            viz[j]=1;

            }
        }

    }
}
int main(){
    int n;
    f >> n;
    tractor(n);
    g << k;
    return 0;
}