Binary Exponentiation · Nhóm: Số học
Lũy thừa nhị phân (Binary Exponentiation), nhóm Số học.
def binpow(base, exp):
result = 1
while exp > 0:
if exp & 1:
result *= base
else:
pass
base *= base
exp >>= 1
return result
Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.