Advertisement
31ph4n70m

Fibonacci_Divisibility_Advanced.d

Nov 25th, 2019
3,764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.83 KB | None | 0 0
  1. // D solution to codabbey challenge 71
  2. import std.stdio;
  3. import std.array;
  4. import std.conv;
  5.  
  6. pure int getidxfib(int mod) {
  7.     int fib1 = 0;
  8.     int fib2 = 1;
  9.     int fib3 = 0;
  10.     int idx = 2;
  11.     while (true) {
  12.         fib3 = (fib1 + fib2) % mod;
  13.         if (fib3 % mod == 0){
  14.           return idx;
  15.         }
  16.         fib1 = fib2;
  17.         fib2 = fib3;
  18.         idx++;
  19.     }
  20. }
  21.  
  22. void main() {
  23.     static ncases = 19;
  24.     int[19] cases = [449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856];
  25.     string[19] RSP;
  26.     string aux = "";
  27.     for (int i = 0; i < RSP.length; i++){
  28.         RSP[i] = to!string(getidxfib(cases[i]));
  29.     }
  30.     const string[] arr = RSP;
  31.     //writeln(join(arr, " "));
  32.     writeln(arr.join(" "));
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement