Cod sursa(job #1699495)

Utilizator andreicoman299Coman Andrei andreicoman299 Data 7 mai 2016 15:42:07
Problema Ciurul lui Eratosthenes Scor 30
Compilator c Status done
Runda Arhiva educationala Marime 0.6 kb
#include <stdio.h>
#include <stdlib.h>
#define MAXN 2000000
#define LIMPR 4000

int low[1+MAXN], primes[LIMPR], ind;
void ciur(int n){
    int i, j;
    for(i=2;i<=n;i++){
        if(!low[i]){
            low[i]=i;
            primes[ind++]=i;
        }
        for(j=0;j<ind && primes[j]<=low[i] && primes[j]*i<=n;j++)
            low[primes[j]*i]=primes[j];
    }
}

int main(){
    int n;
    FILE*fi,*fo;
    fi=fopen("ciur.in","r");
    fo=fopen("ciur.out","w");
    fscanf(fi,"%d", &n);
    ciur(n);
    fprintf(fo,"%d", ind);
    fclose(fi);
    fclose(fo);
    return 0;
}