题目链接: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 ;
}