2018-12-29 19:30:21 +08:00
|
|
|
#coding: utf-8
|
|
|
|
''' mbinary
|
|
|
|
#######################################################################
|
|
|
|
# File : fastPow.py
|
|
|
|
# Author: mbinary
|
|
|
|
# Mail: zhuheqin1@gmail.com
|
2019-01-31 12:09:46 +08:00
|
|
|
# Blog: https://mbinary.xyz
|
2018-12-29 19:30:21 +08:00
|
|
|
# Github: https://github.com/mbinary
|
|
|
|
# Created Time: 2018-12-17 21:39
|
|
|
|
# Description: fast power
|
|
|
|
#######################################################################
|
|
|
|
'''
|
|
|
|
|
|
|
|
def fastPow(a,n):
|
|
|
|
'''a^n'''
|
|
|
|
rst = 1
|
|
|
|
while n:
|
|
|
|
if n%2:
|
|
|
|
rst *=a
|
|
|
|
n>>=1
|
|
|
|
a*=a
|
|
|
|
return rst
|
|
|
|
|
|
|
|
def fastMul(a,b):
|
|
|
|
'''a*b'''
|
|
|
|
rst = 0
|
|
|
|
while b:
|
|
|
|
if b&1:
|
|
|
|
rst +=a
|
|
|
|
b>>=1
|
|
|
|
a*=2
|