### A generalization of the 3x-1 mapping due to Lu Pei

Consider the mapping Td: ℤ → ℤ Let d ≥ 2. Then

Td(n) = n/d if n ≡ 0 (mod d)
Td(n) = ((d+1)n - i)/d if n ≡ i (mod d),  -d/2  < i ≤ d/2, i ≠ 0.
For example, d = 2 gives the 3x-1 mapping:
T2(n) = n/2 if n ≡ 0 (mod 2)
T2(n) = (3n - 1)/2 if n ≡ 1 (mod 2).
This is a special case of a version of a mapping studied by Herbert Möller and is also an example of a relatively prime mapping, in the language of Matthews and Watts, where m0=1 and mi = d+1 for 1 ≤ i < d and where we have the inequality

m0m1⋯md =(d+1)d-1 < dd.
So it seems certain that the sequence of iterates
n, Td(n), Td2(n), ...
always eventually enters a cycle and that there are only finitely many such cycles.

Clearly Td(n) = n for -d/2 < n ≤ d/2.
For d = 3, 6 and 10, we appear to get no other cycles.
It would be interesting to determine all d with this property. See the Table, which was constructed using the author's faster CALC program.

We assume that every trajectory will eventually reach a cycle and use Floyd's method of testing for equality of kth and 2kth iterates for find a cycle element. We list the cycle with smallest absolute value as starting point.

Enter d (2 ≤ d ≤ 100):
Enter starting integer n: