Repeat If x mod m = 0 x=x/m else x = x*p + m - x mod m until x = 1
This problem uses the same logic as the 3x+1 problem. in that when a chosen divisor does not divide x then an appropriate calculation is made to make x divisible by the divisor. The algorithm tends to converge for any x when m is prime and p = m+1. In this case x = km+r for some k and remainder r. We proceed with the algorithm and note
(1) x = (km+r)(m+1) + m - r .
Multiplying this out we get
x = (km^2+km +rm + r + m - r = hm for some h. Thus the operation (1) transforms x into a multiple of m.
We then divide x by m and repeat the process. Eventually we get to the value of 1. For example the iteration for x= 2,m=17,p=18 is
51 3 68 4 85 5 102 6 119 7 136 8 153 9 170 10 187 11 204 12 221 13 238 14 255 15 272 16 289 17 1
See Documents for xdivmxp-r.exe
http://groups.msn.com/BC2LCC/page.msnw?fc_p=%2Fkx%2Bp%20problems&fc_a=0