TITLE: Under what circumstances does this procedure terminate?
QUESTION [5 upvotes]: This earlier question (essentially) asked why the following loop will terminate.  (This is Java code, so assume you're working with signed, 32-bit integers:)
final int initial    = 2;
final int multiplier = 12381923;

for (int i = initial; i != 0; i += i * multiplier)
    ;

Ziyao Wei's excellent answer explained why this process terminates for this particular combination of an initial value and a multiplier.
My question is this - what is a necessary and sufficient condition on initial and multiplier such that this process is guaranteed to terminate?
Thanks!

REPLY [9 votes]: Since i += i * multiplier is equivalent to i *= (multiplier + 1), the conditions for termination are:

initial is zero, and/or
multiplier is odd

Since odd numbers have inverses modulo 2n, multiplying by them can not result in zero (unless it was zero to begin with). Multiplying by an even number irreversibly sets at least one bit to zero.

Perhaps a more intuitive way to explain it comes directly from binary multiplication. 
Just like in decimal, a number of sub-results are added together. In binary, the sub-results are easier to calculate, since when you're calculating the them you only have to multiply by 0 or 1 (and shift). For example (adapted from wiki:binary_multiplier to be modular modulo 24 and with the operands swapped)
  1011
x 1110
======
  1110   (this is 1110 x 1)
  110    (this is 1110 x 1, shifted one position to the left)
  00     (this is 1110 x 0, shifted two positions to the left)
+ 0      (this is 1110 x 1, shifted three positions to the left)
=========
  1010

So, if a multiplicand is odd, the other multiplicand is added in its unshifted version. Observe that adding carries to the left, and so can't affect any digits to the right of its rightmost 1, and no other addition can ever "touch" the rightmost 1 in that number, because from that point on only shifted numbers (with their rightmost 1 either more to the left or throw out completely). So once that rightmost 1 is there it will stay there, and since having a rightmost 1 at all means the number can't be zero, multiplying any nonzero number by an odd number can not result in zero.