Finding Collatz-like rules with many loops This code-challenge is related to the code-golf question Analyzing Collatz-like sequences but the goal is quite different here.

If you are familiar with Collatz-like sequences you can skip to the section "The task".

We define a Collatz-like rule with 3 positive integers:


d &gt; 1 divisor
m &gt; 1 multiplier
i &gt; 0 increment


(In the original Collatz sequence d = 2, m = 3 and i = 1.)

For a Collatz-like rule and a positive integer n starting value we define a sequence s in the following manner:


s(0) = n
if k &gt; 0 and s(k-1) mod d = 0 then s(k) = s(k-1) / d
if k &gt; 0 and s(k-1) mod d != 0 then s(k) = s(k-1) * m + i


An example sequence with d = 2, m = 3, i = 5 and n = 80 will be s = 80, 40, 20, 10, 5, 20, 10, 5, 20, ....

Every sequence will either reach higher values than any given bound (i.e. the sequence is divergent) or get into an infinite loop (for some t and u (t!=u) the s(t) = s(u) equality will be true).

Two loops are said to be different if they don't have any common elements.

The task

You should write a program which finds a Collatz-like rule with many different loops. Your score will be the number of found loops. (You don't have to find all of the possible loops and higher score is better.) 

The program could be specialized in any manner to produce the best score.

For proof the program should output the values of d, m, i and the smallest values from every found loop.

Example

For d=3 m=7 i=8 the loops are 

LOOP 15 5 43 309 103 729 243 81 27 9 3 1
LOOP 22 162 54 18 6 2
LOOP 36 12 4

So a valid proof with a score of 3 could be 

d=3 m=7 i=8 min_values=[1 4 2]


You can validate your result with this Python3 code. The program expects a list of space-separated integers d m i min_value_1 min_value_2 ... as input.
GolfScript, arbitrary score

~:l 2:m.@?):d\1 l,{m\)?d-*}/abs.{1 m 3$)?-*m@)?d-m(*/}+l,/]' '*


This takes an integer on stdin and outputs a sequence with that many loops, in the input format of the Python tester. The online demo runs it for l = 4 and produces output 17 2 1755 117 405 1365 26325; this fork of the tester verifies it.

Explanation

In order to keep it simple, I restricted the analysis to primitive loops: ones with only one division.

(x -&gt; mx + i)^n = (x -&gt; m^n x + (m^n - 1)/(m-1) i)


so this means that I'm looking for solutions to

m^n x + (m^n - 1)/(m - 1)i = dx


or

(m^n - d) x + (m^n - 1)/(m - 1)i = 0


When n &gt; 0, m &gt; 1, m^n - d != 0 this has exactly one solution for x. m - 1 &gt; 0 and m^n - 1 &gt; 0, so in order for the solution to be positive we require m^n - d &lt; 0, and in order for the solution to be an integer we require d - m^n to be a factor of (m^n - 1)/(m - 1)i.

The rest may already be obvious. We pick the desired score, l. We're going to find primitive loops of length 1 to l, so we want d - m^l &gt; 0. To get a smallish output we pick m = 2, d = 2^l + 1. Then to get an easy guarantee of the divisibility constraints we pick i to be the absolute value of (m - d)(m^2 - d)...(m^l - d).