fork(2) download
  1. <?php
  2.  
  3. function fibonacci( $n ) {
  4. $V5 = sqrt( 5 );
  5. $Phi = ( 1 + $V5 ) / 2;
  6. $iPhi = -1 / $Phi;
  7. return round( ( pow( $Phi, $n ) - pow( $iPhi, $n ) ) / $V5 );
  8. }
  9.  
  10. echo fibonacci( 1 ).PHP_EOL;
  11. echo fibonacci( 5 ).PHP_EOL;
  12. echo fibonacci( 100 ).PHP_EOL;
  13.  
  14. ?>
  15.  
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
1
5
3.5422484817926E+20