User blog comment:Ikosarakt1/Apocalyptic function/@comment-25418284-20130322220331/@comment-5529393-20130324025642

Whoops, the cycle length is 4*5^(n-1), not 10^(n-1) for even bases. Note that the cycle length is 4*5^(n-1), not 4*5^(n-1)+n-1;  the first n-1 numbers are not part of the cycle. The reason is that 2^m (mod 10^n) depends on 2^m (mod 5^n) and 2^m (mod 2^n) by the Chinese Remainder Theorem. 2^m (mod 5^n) cycles with a period of length phi(5^n) = 4*5^(n-1);  2^m (mod 2^n) goes through n-1 values before it stabilizes at 0. So the end result is n-1 distinct values and then a cycle of length 4*5^(n-1).

I made a mistake with my probabilistic calculation;  it should be:

(1 - (.999)^(n-2))^(4 * 5^(n-1)) ~ (1 - (.999)^n)^(5^n)

= (1 - (1 - 1/1000)^n)^(5^n) = (1 - ((1 - 1/1000)^1000)^(n/1000))^(5^n)

~ (1 - 1 / (e ^ (n/1000)))^(5^n) = ((1 - 1/(e^(n/1000)))^(e^(n/1000)))^(5^n/(e^(n/1000)))

~ 1 / e^(5^n/e^(n/1000)) = 1 / e^e^(n ln 5 -- n / 1000)

So the probability decreases doubly exponentially, i.e. it goes to zero very fast. Since we know that we don't always have a 666 mod (10^n) for n <= 29784, the probability that there is any n such that we always have a 666 (mod 10^n) is EXTREMELY small.