consider code to find n^k where n is an integer
int power()
{
int ans=1,val=1;
while(k)
{
val=val*n;
if(k&1)ans=ans*val;
k=k>>1;
}
return ans;
}now if n is is a matrix all you have to do is replace * by matrix multiplication algorithm --
consider code to find n^k where n is an integer
int power()
{
int ans=1,val=1;
while(k)
{
val=val*n;
if(k&1)ans=ans*val;
k=k>>1;
}
return ans;
}now if n is is a matrix all you have to do is replace * by matrix multiplication algorithm --