 function log2(n:integer):integer;
   {input condition: n > 0}
   {output condition: returns the floor of the base 2 logarithm of n}
  begin
   if n = 1 then log2 := 0
   else if odd(n) then log2 := log2(n-1)
   else log2 := 1+log2(n div 2)
  end;
