<?php
function fibonacci($n) {
echo "cache "; //está aqui só para mostrar que entrou aqui
return $cache[$n];
}
$a = 0;
$b = 1;
$c = 1;
for ($i = 1; $i < $n ; $i++) {
$c = $a + $b;
$a = $b;
$b = $c;
}
$cache[$n] = $c;
echo "calculou "; //está aqui só para mostrar que entrou aqui
return $c;
}
echo fibonacci(100) ."\n";
echo fibonacci(10) ."\n";
echo fibonacci(100) ."\n";
PD9waHAKZnVuY3Rpb24gZmlib25hY2NpKCRuKSB7CiAgICBzdGF0aWMgJGNhY2hlID0gYXJyYXkoKTsKICAgIGlmIChpc3NldCgkY2FjaGVbJG5dKSkgewogICAgCWVjaG8gImNhY2hlICI7IC8vZXN0w6EgYXF1aSBzw7MgcGFyYSBtb3N0cmFyIHF1ZSBlbnRyb3UgYXF1aQogICAgICAgIHJldHVybiAkY2FjaGVbJG5dOwogICAgfQogICAgJGEgPSAwOwogICAgJGIgPSAxOwogICAgJGMgPSAxOwogICAgZm9yICgkaSA9IDE7ICRpIDwgJG4gOyAkaSsrKSB7IAogICAgICAgICRjID0gJGEgKyAkYjsKICAgICAgICAkYSA9ICRiOwogICAgICAgICRiID0gJGM7CiAgICB9CiAgICAkY2FjaGVbJG5dID0gJGM7CiAgCWVjaG8gImNhbGN1bG91ICI7IC8vZXN0w6EgYXF1aSBzw7MgcGFyYSBtb3N0cmFyIHF1ZSBlbnRyb3UgYXF1aQogICAgcmV0dXJuICRjOwp9CmVjaG8gZmlib25hY2NpKDEwMCkgLiJcbiI7CmVjaG8gZmlib25hY2NpKDEwKSAuIlxuIjsKZWNobyBmaWJvbmFjY2koMTAwKSAuIlxuIjs=