本文共 1607 字,大约阅读时间需要 5 分钟。
2 3 1 20132 3 2 20132 2 1 2013
4144
/*告诉你a,b,n,m,求0 <2^15 , (a-1)^2 #include#include using namespace std;typedef long long ll;struct matrix{ ll mat[2][2];};matrix mul(matrix &a,matrix &b,ll mm){ matrix c; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { c.mat[i][j]=0; for(int k=0;k<2;k++) { c.mat[i][j]+=(a.mat[i][k]*b.mat[k][j]); } c.mat[i][j]%=mm; } } return c;}matrix inti(){ matrix ans; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) ans.mat[i][j]=(i==j); } return ans;}matrix ks(matrix a,ll k,ll mm){ matrix ans=inti(); while(k) { if(k&1) ans=mul(ans,a,mm); a=mul(a,a,mm); k>>=1; } return ans;}int main(){ matrix M; ll a,b,n; ll m; while(~scanf("%lld%lld%lld%lld",&a,&b,&n,&m)) { M.mat[0][0]=a; M.mat[1][1]=a; M.mat[0][1]=b; M.mat[1][0]=1; matrix ans=ks(M,n,m); ll x=ans.mat[0][0]; cout<<(2*x)%m<
转载地址:http://aafci.baihongyu.com/