#include<cstdio>
#define ll long long
struct M{ll x,y;}t;
ll m,x0,n,g;
inline ll mult(ll t,ll k){
ll res=0;
for(;k;k>>=1,t=(t<<1)%m)
if(k&1)res=(res+t)%m;
return res;
}
M operator * (const M &a,const M &b){
return (M){mult(a.x,b.x),(mult(a.x,b.y)+a.y)%m};
}
M operator ^ (M t,ll k){
M res=t;
for(--k;k;k>>=1,t=t*t)
if(k&1)res=res*t;
return res;
}
int main(){
scanf("%lld%lld%lld%lld%lld%lld",&m,&t.x,&t.y,&x0,&n,&g);
t=t^n;printf("%lld",(mult(x0,t.x)+t.y)%m%g);
return 0;
}
2875: [Noi2012]随机数生成器 (矩阵乘法,快速幂,快速乘)
最新推荐文章于 2021-03-22 16:30:08 发布