/*CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C                                                                             C
C  GENERATE FAREY SERIES                                                      C
C  06/11/07 (DKC)							      C
C                                                                             C
C  The Farey series Fn of order n is the ascending series of irreducible      C
C  fractions between 0 and 1 whose denominators do not exceed n.  The         C
C  fractions in the series are generated using the theorem that if h/k,       C
C  h'/k', and h''/k'' are three successive fractions in a Farey series, then  C
C  h'/k' = (h + h'')/(k + k'').  The fraction after two successive fractions  C
C  h/k and h'/k' in the series is then (j*h' - h)/(j*k' - k) where j is some  C
C  positive integer.  Using the theorem that the sum of the denominators of   C
C  successive fractions in a Farey series is greater than the order of the    C
C  series gives j = [(n + k)/k'].                                             C
C                                                                             C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC*/
unsigned int haros2(unsigned int N, unsigned int M, unsigned int *R,
		    unsigned int H, unsigned int K, unsigned int HP,
		    unsigned int KP) {
      unsigned int HPP,KPP,J,OLDM;
//
// STORE CURRENT FRACTIONS
//
      OLDM=M;
      R[M]=(H<<16)|K;
      M=M+1;
      R[M]=(HP<<16)|KP;
//
// FIND FRACTIONS IN FAREY SERIES FOLLOWING H/K, HP/KP
//
L100: J=(N+K)/KP;
      HPP=J*HP-H;
      KPP=J*KP-K;
      H=HP;
      K=KP;
      HP=HPP;
      KP=KPP;
      M=M+1;
      R[M]=(HP<<16)|KP;
      if(KP!=2) goto L100;
//
      return(M-OLDM+1);
      }