UVA 11149 - Power of Matrix

Problem PDF

Solution:

#include 
#include 
#include 
#include 
using namespace std;
#define maxn 44
#define mod 10
int n;
struct matrix{
    int f[maxn][maxn];
};
matrix sum(matrix a,matrix b)
{
    int i,j;
    matrix s;
    for(i=0;i>1;
    }
    return s;
}
matrix work(matrix e,int k)
{
    matrix s,a,b;
    if(k==1)
        return e;
    a=work(e,k/2);
    s=sum(a,mul(a,pows(e,k/2)));
    if(k&1)
        s=sum(s,pows(e,k));
    return s;
}
int main()
{
    int k;
    while(cin>>n>>k)
    {
        if(n==0)
            break;
        int i,j,a;
        matrix e;
        for(i=0;i>a;
                e.f[i][j]=a%10;
            }
        }
        e=work(e,k);
        for(i=0;i
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/11149/11149.cpp