崩溃。。
谁帮忙看一下这50分是错在哪里了
#include<iostream>
#include<cstring>
#define MOD m
#define N 3
typedef long long ll;
using namespace std;
ll m, a, c, x0, n, g, ans;
inline ll mul(ll x, const ll &y){
ll res = 0;
for(ll i = y; i; i >>= 1, x = (x + x) % m)
if(i & 1) res = (res + x) % m;
return res;
}
struct matrix{
ll a[N][N];
matrix(){memset(a,0,sizeof(a));}
}tmp;
matrix operator *(const matrix &x,const matrix &y){
matrix z;
for(int i=0;i<N;i++) for(int j=0;j<N;j++) for(int k=0;k<N;k++){
z.a[i][j]=(z.a[i][j]+x.a[i][k]*y.a[k][j])%MOD;
}
return z;
}
template <typename T>
T ksm(T a, long long b){
T res=a; b--;
while(b){
if(b & 1) res=res *a;
a=a*a;
b>>=1;
}
return res;
}
int main(){
scanf("%lld%lld%lld%lld%lld%lld", &m, &a, &c, &x0, &n, &g);
tmp.a[1][1] = a; tmp.a[1][2] = c; tmp.a[2][2] = 1;
matrix res = ksm(tmp, n); ans = (mul(res.a[1][1], x0) + res.a[1][2]) % m % g;
printf("%lld", ans);
return 0;
}