Advertisement
31ph4n70m

Fibonacci_Divisibility_Advanced.php

Nov 26th, 2019
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2. // php solution to codeabbey challenge 71
  3.  
  4. function getidxfib($modulo){
  5.     $fib1 = 0;
  6.     $fib2 = 1;
  7.     $fib3 = 0;
  8.     $idx = 2;
  9.     while (true){
  10.         $fib3 = ($fib1 + $fib2) % $modulo;
  11.         if ($fib3 % $modulo == 0) {
  12.             return $idx;
  13.         }
  14.         $fib1 = $fib2;
  15.         $fib2 = $fib3;
  16.         $idx++;
  17.     }
  18. }
  19.  
  20. $N_CASES = 19;
  21. $CASES = [449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856];
  22. $RSP = $arrayName = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  23. for($i = 0; $i < 19; $i++){
  24.     $RSP[$i] = getidxfib($CASES[$i]);
  25. }
  26. echo implode(" ", $RSP);
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement