Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function f($n) {
- static $result = [];
- if (isset($result[$n])) {
- return $result[$n];
- }
- if ($n <= 2) {
- $r = $n;
- } else {
- $r = f($n - 1) + f($n - 2);
- }
- $result[$n] = $r;
- return $r;
- }
- echo f(40);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement