title: Calculating the summation of powers of a number modulo a number
body: <p>There are 3 numbers: <code>T, N, M. 1 ≤ T, M ≤ 10^9, 1 ≤ N ≤ 10^18</code> .</p>
  
  <p>What is asked in the problem is to compute <code>[Σ(T^i)]mod(m)</code> where i varies from 0 to n. Obviously, O(N) or O(M) solutions wouldn't work because of 1 second time limit. How should I proceed?</p>