Digit sum of a^b

How to find digit sum of a^b when 1<a<10 and 1<b<4000

#include
using namespace std;
#include
int main()
{
int a,b,t,i,carry,numlen,digi_count,sum,j,x;
cin>>t;
while(t–)
{
sum=0;
cin>>a>>b;
numlen=(int)(b*log10(a))+1;
int ar[numlen];
ar[0]=1;
carry=0;
digi_count=1;
for(i=0;i<b;i++)
{
for(j=0;j<digi_count;j++)
{
x=ar[j]*a+carry;
ar[j]=x%10;
carry=x/10;
}
while(carry>0)
{
ar[digi_count]=carry%10;
carry=carry/10;
digi_count++;
}
}
for(j=0;j<numlen;j++)
sum=sum+ar[j];
cout<<sum<<endl;
}
return 0;
}

def sum_of_digit(a,b):
c = a**b
sum = 0;
while (c != 0):
sum = sum + c%10
c=c/10
return sum
def main():
a=int(raw_input(“a=”))
b=int(raw_input(“b=”))
print sum_of_digit(a,b)