title: Sum of series: 1^1 + 2^2 + 3^3 + ... + n^n (mod m)
body: <p>Can someone give me an idea of an efficient algorithm for large n (say 10^10) to find the sum of above series?</p>
  
  <p>Mycode is getting klilled for n= 100000 and m=200000</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main() {
      int n,m,i,j,sum,t;
      scanf("%d%d",&amp;n,&amp;m);
      sum=0;
      for(i=1;i&lt;=n;i++) {
          t=1;
          for(j=1;j&lt;=i;j++)
              t=((long long)t*i)%m;
          sum=(sum+t)%m;
      }
      printf("%d\n",sum);
  
  }
  </code></pre>