花了一个多小时终于ac了,有时候真的是需要冷静一下重新打一遍才行。
这题就是 |aod(n)| = |1 ax*bx ax*by ay*bx by*ay| |aod(n-1) |
|an*bn | = |0 ax*bx ax*by ay*bx by*ay| |an-1*bn-1 |
|an | = |0 0 ax 0 ay | | a(n-1) |
|bn | = |0 0 0 bx by | | b(n-1) |
|1 | = |0 0 0 0 1 | | 1 |
然后特判n==0的情况就行了
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-9; const int N=10+5,maxn=1<<10+5,inf=0x3f3f3f3f; struct Node{ ll row,col; ll a[N][N]; }; Node mul(Node x,Node y) { Node ans; ans.row=x.row,ans.col=y.col; memset(ans.a,0,sizeof ans.a); for(ll i=0;i<x.row;i++) for(ll j=0;j<x.col;j++) for(ll k=0;k<y.col;k++) ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k])%mod; return ans; } Node quick_mul(Node x,ll n) { Node ans; ans.row=x.row,ans.col=x.col; memset(ans.a,0,sizeof ans.a); for(ll i=0;i<ans.col;i++)ans.a[i][i]=1; while(n){ if(n&1)ans=mul(ans,x); x=mul(x,x); n>>=1; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setiosflags(ios::fixed)<<setprecision(2); ll n,a0,b0,ax,ay,bx,by; while(cin>>n>>a0>>ax>>ay>>b0>>bx>>by){ if(n==0) { cout<<0<<endl; continue; } Node A; A.row=5,A.col=5; memset(A.a,0,sizeof A.a); A.a[0][0]=A.a[4][4]=1; A.a[0][1]=A.a[1][1]=ax*bx%mod; A.a[0][2]=A.a[1][2]=ax*by%mod; A.a[0][3]=A.a[1][3]=ay*bx%mod; A.a[0][4]=A.a[1][4]=ay*by%mod; A.a[2][2]=ax,A.a[2][4]=ay; A.a[3][3]=bx,A.a[3][4]=by; A=quick_mul(A,n-1); Node B; B.row=5,B.col=1; B.a[0][0]=B.a[1][0]=a0*b0%mod,B.a[2][0]=a0,B.a[3][0]=b0,B.a[4][0]=1; B=mul(A,B); cout<<B.a[0][0]%mod<<endl; } return 0; }