Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. <?php
  2.  
  3. function f($n) {
  4. static $result = [];
  5.  
  6. if (isset($result[$n])) {
  7. return $result[$n];
  8. }
  9.  
  10. if ($n <= 2) {
  11. $r = $n;
  12. } else {
  13. $r = f($n - 1) + f($n - 2);
  14. }
  15. $result[$n] = $r;
  16. return $r;
  17. }
  18.  
  19. echo f(40);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement