UVA 11149 - Power of Matrix

UVA Sep 1, 2020

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

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.