Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. k = 4
  2.  
  3. fab = {
  4. 0: 1,
  5. 1: 1,
  6. }
  7.  
  8. def get_f(x):
  9. if x in fab:
  10. return fab[x]
  11.  
  12. fab_x = x * fab[x-1]
  13. fab[fab_x] = fab_x
  14. return fab_x
  15.  
  16. def cal(n, r):
  17. # n! / (r! * (n-r)!)
  18. return get_f(n) / (get_f(r) * get_f(n-r))
  19.  
  20. for n in range(k):
  21. line = []
  22. for r in range(n+1):
  23. line.append(cal(n, r))
  24. print ' '.join([str(x) for x in line])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement