title: Optimized way to handle extremely large number without using external library
body: <p><strong>Optimized way to handle the value of n^n (1 ≤ n ≤ 10^9)</strong></p>
  
  <p>I used <code>long long int</code> but it's not good enough as the value might be (1000^1000)</p>
  
  <p>Searched and found the <code>GMP library</code> <a href="http://gmplib.org/" rel="nofollow">http://gmplib.org/</a> and <code>BigInt class</code> but don't wanna use them. <strong>I am looking for some numerical method to handle this.</strong></p>
  
  <p><strong>I need to print the first and last <em>k</em> (1 ≤ k ≤ 9) digits of <code>n^n</code></strong></p>
  
  <p>For the first <em>k</em> digits I am getting it like shown below (it's bit ugly way of doing it)</p>
  
  <pre><code>num = pow(n,n);
  while(num){
      arr[i++] = num%10;
      num /= 10;
      digit++;
  }
  while(digit &gt; 0){
      j=digit;
      j--;
      if(count&lt;k){
          printf("%lld",arr[j]);
          count++;
      }
      digit--;
  }
  </code></pre>
  
  <p>and for last <em>k</em> digits am using <code>num % 10^k</code> like below.</p>
  
  <pre><code>findk=pow(10,k);
  lastDigits = num % findk;
  enter code here
  </code></pre>
  
  <p><strong>maximum value of k is 9. so i need only 18 digits at max.
  I am think of getting those 18 digits without really solving the complete n^n expression.</strong></p>
  
  <p>Any idea/suggestion??</p>