Cod sursa(job #1133670)

Utilizator omerOmer Cerrahoglu omer Data 5 martie 2014 12:13:10
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include<stdio.h>
using namespace std;
FILE *f,*g;

int pi,N;
bool ok[2000001];

void sift(int i)
    {
        pi++;
        if ((long long)i*i<=N)
        {int s=i*i;
        while(s<=N) {ok[s]=1;s+=i;}}
    }


int main()
{
    int i;
    f=fopen("ciur.in","r");
    g=fopen("ciur.out","w");
    fscanf(f,"%d",&N);
    sift(2);
    i=3;
    while(i<=N)
        {
            if (!ok[i]) sift(i);
            i+=2;
        }
    fprintf(g,"%d",pi);

    return 0;
}