Advertisement
31ph4n70m

Fibonacci_Divisibility_Advanced.dart

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