题目链接:传送门
很明显的距乘
抄一个式子
不会插这种东西
然后就可以套板子了
只不过这里的乘法要快速乘,不然炸long long
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
ll mm, a, c, x0, n, g;
ll fmulti(ll a, ll b, ll ans = 0) {
while (b) {
if (b & 1) ans = (ans + a) % mm;
a = (a + a) % mm;
b >>= 1;
}
return ans;
}
struct node {
int x, y; ll m[3][3];
node multi(node x, node y) {
node z = node{x.x, y.y};
for (int i = 1; i <= z.x; i++)
for (int j = 1; j <= z.y; j++)
for (int k = 1; k <= x.y; k++)
z.m[i][j] = (z.m[i][j] % mm + fmulti(x.m[i][k], y.m[k][j])) % mm;
return z;
}
}ans, tmp;
void fpow(ll b) {
while (b) {
if (b & 1) ans = ans.multi(ans, tmp);
tmp = tmp.multi(tmp, tmp);
b >>= 1;
}
}
int main(int argc, char const *argv[]) {
cin >> mm >> a >> c >> x0 >> n >> g;
ans.x = 1; ans.y = 2; ans.m[1][1] = x0; ans.m[1][2] = 1;
tmp.x = 2; tmp.y = 2; tmp.m[1][1] = a; tmp.m[1][2] = 0; tmp.m[2][1] = c; tmp.m[2][2] = 1;
fpow(n); cout << ans.m[1][1] % g << endl;
}