title: Calculating (A pow B) mod M for very large A and B (stored in string)
body: <p>Link to the problem:
  <a href="https://www.hackerearth.com/problem/algorithm/rhezo-and-big-power/description/" rel="nofollow noreferrer">https://www.hackerearth.com/problem/algorithm/rhezo-and-big-power/description/</a>
  I saw the best submission in which the person calculated A%M (just like how we do on paper), and B%(M-1); then these two came in Integer range and he did log(n) approach to find m^n % M?
  I can't really understand why would he do B%(M-1).</p>