title: C++ : How to calculate modulo of a number raised to large power?
body: <p>I am solving a programming problem where I have to print the answer in the format answer mod 10 ^ 9 + 7, where 'answer' is the actual answer to the problem.</p>
  
  <p>I have figured out the algorithm to solve the problem, however the caveat is that the answer to the problem is always of the format m * 10 ^ n, where</p>
  
  <p>1 &lt;= m &lt;= 8 and 2 &lt;= n &lt;= 10 ^ 18, that is in the answer 10 can be raised to a power as large as 10 ^ 18. Ofcourse, directly calculating 10 ^ n may overflow.</p>
  
  <p>What should I do next?</p>