fork download
  1. count = 0
  2.  
  3. def choose(n,k):
  4. global count; count += 1
  5. if k <= 0:
  6. return 1
  7. elif n < k:
  8. return 0
  9. else:
  10. k = k if k <= n/2 else n - k
  11. return ((n - k + 1)/k)*choose(n, k-1)
  12.  
  13. print "answer: ", choose(500,498)
  14. print "function calls: ", count
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
answer:  124500
function calls:  3