int QuickPower(int N,int time)//計算N^time
{
int ReturnValue=1;//記錄返回值
int Pow=1;//記錄當前已經計算出的多少次冪
int temp=N;//記錄N^i次冪
while(time){
int Bin=time%(2*Pow);//Bin記錄二進制位
if(Bin) {time-=Bin; Bin=1;}//這裏是將time化成二進制的靈活用法
ReturnValue*=(temp*Bin!=0?temp*Bin:1);//仔細體會這一步
temp*=temp;//你懂的
Pow*=2;//你懂的
}
return ReturnValue;