-4

嗨,我可以使用 pow 而不是这样写吗?

                    $round1 = $max / 2;
                    $round2 = $round1 + ($max / 2 / 2);
                    $round3 = $round2 + ($max / 2 / 2 / 2);
                    $round4 = $round3 + ($max / 2 / 2 / 2 / 2);
                    $round5 ...
                    $final = $max - 1;
                    $third = $max;

感谢帮助!

4

2 回答 2

2

你不会碰巧在寻找一种更简单的方法来做到这一点,你会不会:

$round = array($max/2);
for ($i=1;i<$max;$i++)
{
    $round[] = $round[$i -1] + $max/pow(2, $i + 1);
}

当然,array_sum也可能值得一看。

于 2013-08-12T12:24:04.003 回答
-1

尝试这个,

 $rount[0]=0;
 for($i=1;$1<upto n rounds;$i++)
 {
   $rount[i]=$round[i-1]+($max/(2*i));
 }
于 2013-08-12T12:27:28.970 回答