Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)
题目链接: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 (矩阵快速幂)的更多相关文章
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
		
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
 - 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 ...
 - 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 ...
 - codeforces 678D Iterated Linear Function 矩阵快速幂
		
矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵 { g[n] } = {A B} * { g[n-1]} { 1 } {0 1 ...
 - Educational Codeforces Round 13 D:Iterated Linear Function(数论)
		
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...
 - 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 ...
 - Educational Codeforces Round 13
		
http://codeforces.com/contest/678 A:水题 #include<bits/stdc++.h> #define fi first #define se sec ...
 - Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
		
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
 - Educational Codeforces Round 13 C. Joty and Chocolate 水题
		
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...
 
随机推荐
- java 基础学习
			
a+b: import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner c ...
 - Asp.net正则获取html内容
			
1.获取div内容 string str = "tt<u>ss</u><div id=\"test\"><div>< ...
 - Content-Type
			
HTTP Content-type .*( 二进制流,不知道下载文件类型) application/octet-stream .txt text/plain 没有csv这种类型
 - Java [Leetcode 232]Implement Queue using Stacks
			
题目描述: Implement the following operations of a queue using stacks. push(x) -- Push element x to the b ...
 - 《C++ Primer 4th》读书笔记 第10章-关联容器
			
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936464.html
 - Android Thread.UncaughtExceptionHandler捕获
			
在Java 的异常处理机制中:如果抛出的是Exception异常的话,必须有try..catch..进行处理,属于checked exception.如果抛出的是RuntimeException异常的 ...
 - POJ 2549 Sumsets
			
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10593 Accepted: 2890 Descript ...
 - c#写入Mysql中文显示乱码 解决方法 z
			
mysql字符集utf8,c#写入中文后,全部显示成?,一个汉字对应一个? 解决方法:在数据库连接字符串中增加字符集的说明,Charset=utf8,如 MySQLConnection con = n ...
 - excel 经验总结
			
1.2007版excel表格中怎么将使用字母+数字下拉排序 比如:A201110300001怎么在excel表格中往下拉的时候变成A201110300002.A201110300003…… 方法: 因 ...
 - linux命令——磁盘管理pwd
			
Linux中用 pwd 命令来查看”当前工作目录“的完整路径(绝对路径). 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录.在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的 ...