Re: [問題] a的b次方實作時間logb之遞迴寫法
http://nopaste.csie.org/b7518
完全只是把原po的非遞迴改成遞迴 = =
int fastpow_initial(int a, int b)
{
return fastpow_recursive(a,b,1);
}
int fastpow_recursive(int a, int b, int temp)
{
if(b == 0)
return temp;
else if(b&1)
return fastpow_recursive(a*a,b>>1,temp*a);
else
return fastpow_recursive(a*a,b>>1,temp);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.168.169.77
推
03/24 23:56, , 1F
03/24 23:56, 1F
推
03/25 00:14, , 2F
03/25 00:14, 2F
→
03/25 00:16, , 3F
03/25 00:16, 3F
推
03/25 00:21, , 4F
03/25 00:21, 4F
討論串 (同標題文章)
完整討論串 (本文為第 4 之 6 篇):