I have wrote below program to extract the last five digits of n number that is the answer of function below:
n = 1^1 + 2^2 + ... + m^m
where m is given by the user. The program works all right for small number but it will not work for m as big as 100^100.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n;
cin>>n;
intmax_t a[n],num,rem;
a[0]=0;
for (int i=1; i<=n; i++){
a[i] = a[i-1]+pow(i,i);
}
num=a[n];
int b[5];
for (int i = 1; i <=5; i++) {
rem = fmod(num,10);
b[i]=rem;
num = num/10;
}
for (int i = 1; i <=5; i++) {
cout<< b[i];
}
return 0;
}