31ph4n70m

Fibonacci_Divisibility_Advanced.d

Nov 25th, 2019
698
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×