{ Program to calculate the factorial of a number N, using a doubly-recursive
  divide-and-conquer algorithm. The reason why anybody would want to write
  it in such a bizarre way is left as something for you to puzzle over.}

program doubly_recursive_factorial( input, output );
var 
  N, count, fact : integer;

  function dfactorial( First, Last: integer ): integer;
  var Mid: integer;
  begin
    if First = Last
    then dfactorial := First
    else
      begin
	Mid := (First+Last) div 2;
	dfactorial := dfactorial( First, Mid ) * dfactorial( Mid+1, Last )
      end
  end; { fact }

begin
  { Get N from the user }
  write( 'N = ' ); readln(N);

  { Negative N is not allowed. It's also convenient to exclude N=0 in this
    version. }
  if N < 1
  then 
    writeln( 'Cannot take the factorial of a negative number' )
  else
    begin
      fact := dfactorial(1,N);
      writeln( 'Factorial ', N:1, ' = ', fact:1 );
    end; { N >= 1 }
end.
