Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

$N$ can be at most $10^{10}$ and $M$ can be at most $10^7$. How can I find the first three digits of $N^M$ ?

Is there an easy way to find this like the process of finding last digit ?

share|cite|improve this question
If $N$ and $M$ are so small, you might as well just calculate $N^M$ rather than waste time thinking of a smarter method. – Chris Eagle Nov 1 '12 at 11:52
what if they are very large ? – johnsmith Nov 1 '12 at 12:00

Use logarithms.

If $X = N^M$, compute $z = 3 + (\log_{10} X \mod 1)$ and then round $y = 10^z$ down to the next integer. This should work for $X \ge 10^3$ and should give a correct answer in IEEE arithmetic for the desired range of $N$ and $M$. For smaller X$, just compute it directly.

share|cite|improve this answer
Is not $(\log_{10} X \mod 1)$ always zero? or you use mod with a different meaning? And $10^z$ is always a multiple of 10, that can't be most significant 3 digits of any $N^M$ – sowrov May 21 '13 at 9:50
$\log_{10} X \mod 1$ is the fractional part of $\log_{10} X$. – Hans Engler May 21 '13 at 17:37
So, I suppose that in the place of 3 it can be any number between 1 and $M*\lceil \log_{10}X \rceil$ – xpy Jan 26 '14 at 14:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.