代码拉取完成,页面将自动刷新
#include <iostream>
using namespace std;
const int MaxSize = 2; //It depends on the problem (2 for computing Fibonacci series)
const int mod = 1e9+7; //It depends on the problem as you may don't need it
struct Matrix{
long long mat[MaxSize][MaxSize];
};
Matrix matMul(Matrix a , Matrix b)
{
Matrix ans; int k;
for(int i = 0 ; i < MaxSize ; i++)
for(int j = 0 ; j < MaxSize ; j++){
for(ans.mat[i][j] = k = 0 ; k < MaxSize ; k++){
long long sum = (a.mat[i][k] * b.mat[k][j]) % mod;
ans.mat[i][j] = (ans.mat[i][j] + sum) % mod;
}
}
return ans;
}
Matrix Identity(){
Matrix res;
for(int i = 0 ; i < MaxSize ; i++)
for(int j = 0 ; j < MaxSize ; j++)
res.mat[i][j] = (i == j);
return res;
}
Matrix Power(Matrix base, long long pw)
{
Matrix ans = Identity();
while(pw){
if(pw & 1) ans = matMul(ans , base);
base = matMul(base, base);
pw >>= 1;
}
return ans;
}
int main(){
// Matrix Power is a technique not a specific problem
// So I wrote just the template of its code.
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。