include Math

class Integer

  def permutation(k)
    (self-k+1 .. self).inject(:*)
  end

  def combination(k)
    self.permutation(k) / (1 .. k).inject(:*)
  end

  def big_permutation(k)
    exp( lgamma_plus(self) - lgamma_plus(self -k)) 
  end

  def big_combination(k)
    exp( lgamma_plus(self) - lgamma_plus(self - k) - lgamma_plus(k))
  end

  private
  def lgamma_plus(n)
    lgamma(n+1)[0]  
  end

end

p 12.permutation(9)               
p 12.big_permutation(9)           
p 60.combination(53)              
p 145.big_permutation(133)        
p 900.big_combination(450)        
p 1000.big_combination(969)       
p 15000.big_permutation(73)       

p 15000.big_permutation(74)       

p 15000.permutation(74)