# RecursiveclassSolution:""" @param a, b, n: 32bit integers @return: An integer """deffastPower(self,a,b,n):# write your code hereifn==0:return1%bifn==1:returna%bresult=self.fastPower(a,b,n/2)result=(result*result)%b# 若n是奇数,需要多乘一次ifn%2==1:result=(result*a)%breturnresult# ArrayclassSolution:""" @param a, b, n: 32bit integers @return: An integer """deffastPower(self,a,b,n):# write your code here# (a * b) % p = ((a % p ) * (b % p)) % pifn==0:return1%barray=[1]*(n+1)array[0]=1%barray[1]=a%bforiinrange(2,n+1):j=iwhilej>0:ifj==1:array[i]*=array[1]breakelse:array[i]*=array[j/2];j-=j/2array[i]%=breturnarray[n]