31ph4n70m

Fibonacci_Divisibility_Advanced.kt

Nov 26th, 2019
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.73 KB | None | 0 0
  1. // Kotlin solution to codeabbey challenge 71
  2. fun getidxfib(mod: Int): Int{
  3.     var fib1: Int = 0
  4.     var fib2: Int = 1
  5.     var fib3: Int = 0
  6.     var idx: Int = 2
  7.     while (true){
  8.         fib3 = (fib1 + fib2) % mod
  9.         if (fib3 % mod == 0) {
  10.             return idx
  11.         }
  12.         fib1 = fib2
  13.         fib2 = fib3
  14.         idx++
  15.     }
  16. }
  17.  
  18. fun main(args: Array<String>) {
  19.     var N_CASES = 19
  20.     var CASES: IntArray = intArrayOf(449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856)
  21.     var RSP = IntArray(19)
  22.     for(x in 0 until 19){
  23.         RSP[x] = getidxfib(CASES[x])
  24.     }
  25.     println(RSP.joinToString(" "))
  26. }
Add Comment
Please, Sign In to add comment