php 1,1,2,3,5,8,13,21,34...求第30位的数是多少?

php 1,1,2,3,5,8,13,21,34...求第30位的数是多少?

// 1,1,2,3,5,8,13,21,34 数字的规律
// 前面两个数相加等于后面那个数。1+1=2 , 2+3=5 ...
// 时间复杂度 : O(1)  空间复杂度: O(1)

<?php
$arr = [1, 1];
for ($i=2; $i<30; $i++) {
    $arr[$i] = $arr[$i-1] + $arr[$i-2]; 
}
echo end($arr); // 832040

相关文章

SHA256WithRSA 生成签名
消息推送
set_time_limit 不会把已经执行的时间 和 sleep 的时间计算在...
php分解代码片段$colors  = "red,blue,...
php替换代码片段str_replace ($search, $replace,...
php curl示例function getUrl($url){   &nb...