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;