Advertisement
31ph4n70m

Fibonacci_Divisibility_Advanced.js

Nov 25th, 2019
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // js solution to codeabbey challenge 71
  2. function getidxfib(mod){
  3.     let fib1 = 0;
  4.     let fib2 = 1;
  5.     let fib3 = 0;
  6.     let idx = 2;
  7.     while (true){
  8.         fib3 = (fib1 + fib2) % mod;
  9.         if (fib3 % mod === 0){
  10.           return idx.toString();
  11.         }
  12.         fib1 = fib2;
  13.         fib2 = fib3;
  14.         idx++;
  15.     }
  16. }
  17.  
  18. N_CASES = 19;
  19. CASES = [449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856];
  20. RSP = [];
  21. for (var i = 0; i < CASES.length; i++) {
  22.     RSP.push(getidxfib(CASES[i]))
  23. }
  24. console.log(RSP.join(" "));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement