[luoguP3390]【模板】矩阵快速幂
2024-08-30 20:43:09
模板不解释。
——代码
#include <cstdio>
#include <cstring>
#define LL long long int n;
LL k;
const int p = 1e9 + ; struct Matrix
{
LL a[][];
Matrix()
{
memset(a, , sizeof(a));
}
}; inline Matrix operator * (const Matrix x, const Matrix y)
{
Matrix ans;
int i, j, k;
for(i = ; i < n; i++)
for(j = ; j < n; j++)
for(k = ; k < n; k++)
ans.a[i][j] = (ans.a[i][j] + x.a[i][k] * y.a[k][j]) % p;
return ans;
} int main()
{
int i, j;
Matrix ans, trs;
scanf("%d %lld", &n, &k);
for(i = ; i < n; i++) ans.a[i][i] = ;
for(i = ; i < n; i++)
for(j = ; j < n; j++)
scanf("%lld", &trs.a[i][j]);
while(k)
{
if(k & ) ans = ans * trs;
trs = trs * trs;
k >>= ;
}
for(i = ; i < n; i++)
{
for(j = ; j < n; j++) printf("%d ", ans.a[i][j]);
puts("");
}
return ;
}
最新文章
- welcome-file-list设置问题之css,js文件无法加载
- web程序员该学习什么
- Windows下使用命令行启动php
- iOS开发——项目实战总结&;数据持久化分析
- 关于版本号:alpha、beta、rc、stable
- Tomacat服务器的安装和配置
- C++中 _itoa_s方法简介
- 工控主板对ISO7816智能卡标准的支持
- effective c++ 条款18 make interface easy to use correctly and hard to use incorrectly
- jQuery DataTable 删除数据后重新加载
- hibernate切换数据源
- 在CentOS 7.3 中安装 NVIDIA GT730 显卡驱动
- qnx gpio
- Git使用过程中的问题
- 【HDU 4343】Interval query(倍增)
- Android开发中常见的设计模式(四)——策略模式
- jmeter 连接 MySql
- Linux_CentOS-服务器搭建 <;三>; 补充
- Qt入门之基础篇 ( 一 ) :Qt4及Qt5的下载与安装
- android笔记:Service