#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64

off64_t  fact64
(
   off64_t lF
);

void main
(
   int   iArgs    ,
   char *apsArgs[]
)
{
   int       i        = 0;
   char     *pcArgN   = NULL;
   char     *pcArgR   = NULL;
   long      l        = 0L;
   off64_t   lN       = 0ULL;
   off64_t   lR       = 0ULL;
   off64_t   lNe      = 0ULL;   // N!
   off64_t   lNmR     = 0ULL;   // N-R

   //

   for (i = 0; i < iArgs; i++)
   {
      if (0 == strncmp ("-n=", apsArgs[i], 3))         // -n
      {
         pcArgN = apsArgs[i] + 3;
         lN     = atol (pcArgN);
      }
      else if (0 == strncmp ("-r=", apsArgs[i], 3))        // -r
      {
         pcArgR = apsArgs[i] + 3;
         lR     = atol (pcArgR);
      }
   }

   //

   printf ("pcArgN=[%s] lN=%I64u\n", pcArgN, lN);
   printf ("pcArgR=[%s] lR=%I64u\n", pcArgR, lR);


   // p = n!/(n-r)!
   // c = n!/r!(n-r)!

   lNe = fact64 (lN);
   printf ("lNe=%I64u\n", lNe);


   // Exit

   return;
}

off64_t  fact64
(
   off64_t lF
)
{
   off64_t N = 0ULL;
   off64_t F = 0ULL;

   // FxF-1

   N = lF;
   F = 1;

   while (N >= 2)
   {
      printf ("N=%I64u\n", N);
      F = F * N;
      N = N - 1;
   }

   return (F);
}
