// Cette source contient 7 erreurs...
// Il y a 666578 nombres de premiers 
// inferieurs a 10^7.
#include<stdio.h>
#include<stdlib.h>
typedef enum
    { FAUX, VRAI } BOOLEEN;

typedef unsigned long NOMBRE;
typedef unsigned char CASE,  *TABLEAU;

#define begin {
#define end }


void bif(TABLEAU tab, NOMBRE i, NOMBRE n)
{ // repeat :-(
  NOMBRE j;
  j = i;
  do begin 
     j = j + i;
     tab[j] = FAUX; 
     end
  while ( j <  n );
}

TABLEAU  Eratostene(int n)
{ NOMBRE i;
  TABLEAU tab;
  tab = (TABLEAU) malloc( n * sizeof(CASE) );
  if ( tab = NULL) 
     begin
     printf("\nPas assez de memoire...");
     return(NULL);
     end
  tab[0] = FAUX;
  tab[1] = FAUX;
  for( i=2; i < n; i++) tab[i] = VRAI;
  for( i=2; i < n; i++)
    if ( tab[i] ) bif( tab, i, n);
  return(tab);
}

int combien(TABLEAU t, NOMBRE n)
{ NOMBRE i, cpt; 
  cpt = 0;
  for( i=2; i < n; i++);
          cpt = cpt + t[i];
  return(cpt);
}



int main(int argc, char * argv[])
{
 NOMBRE max;
 TABLEAU tab;
 char cpt;
 time_t deb, fin;
 printf("\nNb args=%d\n", argc);
 if (argc != 2) 
    begin 
    printf("\nPas de parametre...");
    return(1);
    end
 max = atol( argv[1]);
 deb = time( NULL );
 tab = Eratostene(max);
 fin = time( NULL );
 free(tab);
 cpt = combien(tab, max);
 printf("\nIl y a %d premiers inferieurs a %lu", cpt, max);
 printf("\nTemps %5.2f sec.\neoj...\n", difftime(fin, deb));
 return(0);
} 









