I have been given the following problem:

Find a positive three digit number all of whose integral powers end with those same three digits. Can you generalise this to k digits?

Numbers of this nature are called automorphic numbers, and I have found that 625 and 376 are both automorphic. As far as generalising this is concerned, I have come up with a recursive formula that will calculate the kth digit, given you know an automorphic number of length k-1 digits. I have been unable to find anything online or in books that gives such a formula- wikipedia has a formula for finding a number of length 2k digits (n'), given an automorphic number of length k (n) which is

n'=(3n^2-2n^3)mod 10^2k.

Does anyone know any other formulae for this problem? or the proof of the above formula?

Many thanks.