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 ...
随机推荐
- org/apache/commons/discovery/tools/DiscoverSingleton
是编写的调用web service服务器的客户端程序编译时出错. Exception in thread "main" java.lang.NoClassDefFoundError ...
- [ASP.NET 技术点滴] Jquery 前端验证
先上HTML代码: <form id="login" name="login" action="~/f_login/Login" me ...
- codevs 1197 Vigenère密码
开始做NOIP啦.. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- 【C#学习笔记】写文件
using System; using System.IO; namespace ConsoleApplication { class Program { static void Main(strin ...
- ffmpeg的内部Video Buffer管理和传送机制
ffmpeg的内部Video Buffer管理和传送机制 本文主要介绍ffmpeg解码器内部管理Video Buffer的原理和过程,ffmpeg的Videobuffer为内部管理,其流程大致为:注册 ...
- 私有pod简记
http://www.jianshu.com/p/7a82e977281c http://www.jianshu.com/p/ddc2490bff9f 两个工程 1 代码工程 在github上创建一个 ...
- 函数与关系实例,函数运算与SQL,试验与关系元组
函数是一个集合,它的每个元素都是二元组或多元组.例如 f = { (x, y) | x∈R & y∈R & y = 2x } ,g = { (x, y, z) | (x, y, z)∈ ...
- Cocos2d提供的字体(图文并茂)
1.AppleGothic CCLabelTTF *myLabel = [CCLabelTTF labelWithString:@"AppleGothic" fontName:@& ...
- Redis Sentinel机制与用法
概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都 ...
- UI特效--Android利用ViewFlipper实现屏幕切换动画效果
.屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面:一个个性化设置页面.2.介绍ViewFilpper类ViewFl ...