ClavinJune

math materi CP

Oct 7th, 2018
233
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def pow(a,b):
  2.   if b == 0: return 1
  3.   if b % 2 == 0:
  4.     x = pow(a, b/2)
  5.     return x * x
  6.   else:
  7.     return f(a,b-1) * a
  8. # pow O(lg(n))
  9. ##################################################################
  10. '''
  11. kpk => kalikan semua angka pangkat terkecil
  12. fpb => kalikan angka paling kecil yang sama dengan pangkat terbesar
  13.  
  14. a * b == fpb(a,b) * kpk(a,b)
  15.  
  16. fpb(20, 35) == fpb(20, 35%20)
  17. fpb(20, 15) == fpb(5, 15)
  18. fpb(5, 0) == 5
  19.  
  20. fpb(a, b):
  21.  return fpb(b, a%b)
  22.  
  23. kpk(a, b) == a*b / fpb(a,b)
  24. MINDBLOOOWWNN
  25.  
  26. using memoization for Combination
  27. '''
RAW Paste Data Copied