题目链接:http://codeforces.com/problemset/problem/678/D

简单的矩阵快速幂模版题

矩阵是这样的:

 #include <bits/stdc++.h>
using namespace std;
typedef __int64 LL;
struct data {
LL mat[][];
};
LL mod = 1e9 + ; data operator *(data a , data b) {
data res;
for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) {
res.mat[i][j] = ;
for(int k = ; k <= ; ++k) {
res.mat[i][j] = (a.mat[i][k] * b.mat[k][j] % mod + res.mat[i][j]) % mod;
}
}
}
return res;
} data operator ^(data a , LL n) {
data res;
for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) {
res.mat[i][j] = i == j;
}
}
while(n) {
if(n & )
res = res * a;
a = a * a;
n >>= ;
}
return res;
} int main()
{
LL a , b , n , x;
cin >> a >> b >> n >> x;
data temp , res;
temp.mat[][] = a % mod , temp.mat[][] = , temp.mat[][] = b % mod, temp.mat[][] = ;
res.mat[][] = x % mod , res.mat[][] = , res.mat[][] = res.mat[][] = ;
temp = temp ^ n;
res = res * temp;
cout << res.mat[][] << endl;
return ;
}

Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)的更多相关文章

  1. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

  2. Educational Codeforces Round 13——D. Iterated Linear Function(矩阵快速幂或普通快速幂水题)

      D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input ...

  3. Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理

    D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. codeforces 678D Iterated Linear Function 矩阵快速幂

    矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵  { g[n] }    =  {A   B}  * { g[n-1]} {   1   }         {0   1 ...

  5. Educational Codeforces Round 13 D:Iterated Linear Function(数论)

    http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  6. Educational Codeforces Round 13 A、B、C、D

    A. Johny Likes Numbers time limit per test 0.5 seconds memory limit per test 256 megabytes input sta ...

  7. Educational Codeforces Round 13

    http://codeforces.com/contest/678 A:水题 #include<bits/stdc++.h> #define fi first #define se sec ...

  8. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  9. Educational Codeforces Round 13 C. Joty and Chocolate 水题

    C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...

随机推荐

  1. UVa 116 (多段图的最短路) Unidirectional TSP

    题意: 有一个m行n列的正整数环形矩阵(即矩阵第一行的上一行是最后一行,最后一行的下一行是第一行),从第一列的任意位置出发,每次只能向右,右上,右下三个方向行走,输出路径及路径上所有数之和的最大值,多 ...

  2. 纯CSS3带动画效果导航菜单

    随着互联网的发展,网页能表现的东西越来越多.由最开始单纯的文字和链接构成的网页,到后来的表格布局,再到div+css模式,现在发展到了html+css3.网页能表达的东西越来越多,css3兴起已经很多 ...

  3. 搜集的一些RTMP项目,有Server端也有Client端

    查询一些RTMP的协议封装时找到了一些RTMP开源项目,在这里列举一下,以后有时间或是有兴趣可以参考一下: just very few of them. Red5 only contains a se ...

  4. 【JSP】JSP检查字符串是否为数字

    //判断是否是正整数 function IsNum(s) { if(s!=null){ var r,re; re = /\d*/i; //\d表示数字,*表示匹配多个数字 r = s.match(re ...

  5. 【转】WPS文档怎么清除格式

    原文网址:http://jingyan.baidu.com/article/c74d600060dc4a0f6a595d21.html 我们知道有时候如果我们粘贴了别的地方的文字到自己的文档里来,就会 ...

  6. Android 如何使用juv-rtmp-client.jar向Red5服务器发布实时视频数据

    使用juv-client-client.jar主要是尽快地完成毕业设计里面手机端向网页端发送实时视频的功能,由于实习和做毕业设计的时间冲突,因此完成毕业设计只花了1个多月时间. (万恶的形式主义,论文 ...

  7. 【转】匹配dll(exe)和pdb方法

    1. 静态检查windbg 调试工具包中有一个工具symchk.exe, 选项很多, 下面一个简单的用法可以检查一个 test.exe能不能找到与它匹配的PDB: 这是成功的情形. 下面来个失败的作为 ...

  8. HDU 5879 Cure

    Cure Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. Matlab编程实例(1) 移动平均

    MATLAB数字信号处理作业,把自己写的程序发上来..欢迎交流~ QQ 五幺九七九零六四   首先是任意点移动平均: 主程序:mov_average_main.m (运行) 函数:mov_averag ...

  10. 向Window BCD 文件添加VHD开机启动项的相关笔记

    ******************************************************************************** * BCD_YE_MIN文件说明:(精 ...