TITLE: Last $n$ digits of $a^b$
QUESTION [25 upvotes]: Last year I came acoss the following problem in a mathematics competition

What are the last $2$ digits of $2012^{2012}$? $\ \ \ \ \ $(Ans: 56)

I found the last two digits using the standard technique involving some modular arithmetic.
Another student came up with a very clever technique that did not rely on modular arithmetic but rather on  logarithms and the floor function (scientific calculators were allowed, but no graphing calculators or computer algebra systems). I've forgotten the details of this technique, which was really just a function that could be written in a single line, but remember that it easily generalized to give the last $n$ digits of any number of the form $a^b$ without causing overflow errors on little scientific calculators, even with sizable $a$ and $b$.
I've searched stackexchange and the web for information on this technique but found nothing. I spent a fair amount of time thinking about the problem but not made any progress. Has anyone seen such a technique? If so, please help me reproduce the function he used.
I am specifically interested in the technique described above; without any modular arithmetic, Chinese Remainder Theorem, Euler's Generalization, Repeated Squaring, etc.

REPLY [2 votes]: Are you sure the problem asked about the last few digits? If it was first few digits, the one-line solution using logarithms would sounds a lot more likely:
$$g(a,b,n)=\left\lfloor 10^{b\log_{10}a - \lfloor b\log_{10}a\rfloor + 1 + n} \right\rfloor$$
Of course, this is just a disguised version of $\left\lfloor \frac{a^b}{10^{k-n}}\right\rfloor$, where $k$ is the number of digits of $a^b$.