Submitted on CB, but TLE on testcase 14 on spoj . How to resolve?

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define nL “\n”
#define MOD 98765431

vector c;
ll k;

vector<vector> multiply(vector<vector> A, vector<vector> B)
{
vector<vector> C(k+1, vector(k+1));

for(ll i = 1; i <= k; i++)
{
    for(ll j = 1; j <= k; j++)
    {
        for(ll x = 1; x <= k; x++)
        {
            C[i][j] = (C[i][j] + (A[i][x] * B[x][j]) % MOD) % MOD;
        }
    }
}

return C;
}

vector<vector> power(vector<vector> A, ll p)
{
if(p == 1)
return A;

if(p&1)
{
    return multiply(A, power(A, p-1));
}

vector<vector<ll>> X = power(A, p/2);
return multiply(X, X);

}

int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

ll t, num ;
cin >> k >> t;

for(ll i = 1; i <= k; i++)
{
    cin >> num;
    c.push_back(num);
}

// cal F1
vector<ll> F1(k+1);
for(ll i = 1; i <= k; i++)
{
    F1[i] = c[i-1];
}

// creating Transformation matrix T
vector<vector<ll>> T(k+1, vector<ll>(k+1));

for(ll i = 1; i <= k; i++)
{
    for(ll j = 1; j <= k; j++)
    {
        if(i == j)
            T[i][j] = 0;
        else
            T[i][j] = 1;
    }
}    

T = power(T, t);

// cal ans
vector<ll> ans(k+1);
for(ll i = 1; i <= k; i++)
{
    for(ll j = 1; j <= k; j++)
    {
        ans[i] = (ans[i] + (T[i][j] * F1[j]) % MOD) % MOD ;
    }
}

for(ll i = 1; i <= k; i++){
    cout << ans[i] << nL;
}

return 0;

}

hi @devang_11912089
try this -->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.