tjut 4686
来源:互联网 发布:淘宝卖家上传视频教程 编辑:程序博客网 时间:2024/06/08 09:56
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int V = 100000 + 50;const int mod = 1000000000 + 7;const int MaxN = 5;struct Matrix{ __int64 mat[MaxN][MaxN];};Matrix init, Pow;__int64 n, A0, Ax, Ay, B0, Bx, By;Matrix multi(Matrix a, Matrix b) { Matrix ans; for(int i = 0; i < MaxN; ++i) for(int j = 0; j < MaxN; ++j) { __int64 sum = 0; for(int k = 0; k < MaxN; ++k) sum = (sum + a.mat[i][k] * b.mat[k][j] % mod) % mod; ans.mat[i][j] = sum; } return ans;}Matrix MatrixQuickPow(Matrix a, __int64 b) { Matrix ans = init; while(b) { if(b & 1) ans = multi(ans, a); b /= 2; a = multi(a, a); } return ans;}int main() { while(~scanf("%I64d", &n)) { scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &A0, &Ax, &Ay, &B0, &Bx, &By); if(!n) { printf("0\n"); continue; } init.mat[0][0] = 1; init.mat[0][1] = A0; init.mat[0][2] = B0; init.mat[0][3] = init.mat[0][4] = A0 * B0 % mod; Pow.mat[0][0] = Pow.mat[4][4] = 1; Pow.mat[0][1] = Ay; Pow.mat[0][2] = By; Pow.mat[0][3] = Pow.mat[0][4] = Ay * By % mod; Pow.mat[1][1] = Ax; Pow.mat[2][2] = Bx; Pow.mat[1][3] = Pow.mat[1][4] = Ax * By % mod; Pow.mat[2][3] = Pow.mat[2][4] = Ay * Bx % mod; Pow.mat[3][3] = Pow.mat[3][4] = Ax * Bx % mod; /*for(int i = 0; i < MaxN; ++i) { for(int j = 0; j < MaxN; ++j) printf("%I64d ", Pow.mat[i][j]); printf("\n"); }*/ Matrix ans = MatrixQuickPow(Pow, n - 1); printf("%I64d\n", ans.mat[0][4]); }}
0 0
- tjut 4686
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- BestCoder #85 A,B,C
- 懒加载
- 开博客,走这条路的初衷与自勉记录
- frameset和iframe框架讲解
- jQuery 从零开始学习 (三) 属性与css样式
- tjut 4686
- 单例模式的设计
- Codeforces 702D - Road to Post Office
- 暑期集训训练3练习题B - Toxophily(HDU2298)
- PhantomJS快速入门教程(服务器端的 JavaScript API 的 WebKit)
- HashMap HashTable ConcurrentHashmap
- Java反射获取泛型
- Stage5--Python GUI编程TKinter
- 粉扑怎么用如何用粉扑上粉底