题目链接: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. 自定义sublime代码片段

    sublime text 已经有一些他们内置的一些代码片段,但是有时候,这些并不能满足我们,这就需要我们自定义一些代码片段. 步骤如下: 1.打开sublime text 2.选择 tools -&g ...

  2. 代码实现获取log日志和logcat使用方法

    代码实现获取log日志new Thread(new Runnable() {                        @Override                        publi ...

  3. Android安卓开发中图片缩放讲解

    安卓开发中应用到图片的处理时候,我们通常会怎么缩放操作呢,来看下面的两种做法: 方法1:按固定比例进行缩放 在开发一些软件,如新闻客户端,很多时候要显示图片的缩略图,由于手机屏幕限制,一般情况下,我们 ...

  4. 函数fsp_alloc_from_free_frag

    /**********************************************************************//** Allocates a single free ...

  5. UVa 12034 (递推) Race

    题意: 有n个人赛马,名次可能并列,求一共有多少种可能. 分析: 设所求为f(n),假设并列第一名有i个人,则共有C(n, i)种可能,接下来确定后面的名次,共有f(n-1)种可能 所以递推关系为: ...

  6. 全球最受欢迎的十大Linux发行版(图)

    帮助新的Linux用户在越来越多的Linux发行版中选择最合适的操作系统,是创建这个网页的原因.它列出了迄今为止最流行的10个Linux发行版(另外增加的是FreeBSD,到目前为止最为流行的BSD系 ...

  7. codevs 3732 解方程

    神题不可言会. f(x+p)=f(x)(mod p) #include<iostream> #include<cstdio> #include<cstring> # ...

  8. VB程序逆向反汇编常见的函数

    VB程序逆向常用的函数 1) 数据类型转换: a) __vbaI2Str    将一个字符串转为8 位(1个字节)的数值形式(范围在 0 至 255 之间) 或2 个字节的数值形式(范围在 -32,7 ...

  9. I.MX6 Android netperf

    /***************************************************************************** * I.MX6 Android netpe ...

  10. Java [Leetcode 122]Best Time to Buy and Sell Stock II

    题目描述: Say you have an array for which the ith element is the price of a given stock on day i. Design ...