Matrix multiplication
#include <bits/stdc++.h> #define LL long long#define MOD 1000000007using namespace std; LL MMM (int a, int b) {return ((a%mod) * (LL) (b%mod))%mod;} LL x[4], a[4], t[4]; ll* mult (LL *a,ll *b) {x[0]=mmm (a[0],b[0]) +mmm (a[1],b[2]); X[0]%=mod;x[1]=mmm (a[0],b[1]) +mmm (a[1],b[3]); x[1]%=MOD;x [2]=mmm (A[2],b[0]) +mmm (a[3],b[2]) x[2]%=mod;x[3]=mmm (a[2],b[1]) +mmm (a[3],b[3]); X[3]%=mod;return x;} void print (LL *a) {cout<<a[0]<< "" <<a[1]<<endl;cout<<a[2]<< "" <<a[3]< <endl;} LL e[4]={1,0,0,1}; ll s[4]={0,-1,1,1};void eq (ll *a,ll *b) {for (int i=0;i<4;i++) a[i]=b[i];} int main () {int T, P;long long F1, f2;cin>>t;for (int i=1; i<=t; i++) {Cin>>f1>>f2;cin>>p;p--;eq (T, s), if (p%2==0) {eq (A, e);} else {eq (A, t);} P=p>>1;while (p>0) {eq (T,mult (t,t)), if (p%2==1) {eq (A,mult (a,t));} p=p>>1;} Long Long ans = ((f1*a[0]+mod)%mod + (f2*a[2]+mod)%mod+mod)%mod;if (ans<0) {Cout<<ans+mod<<endl;} Else{cout<<ans<<endl;}} RetUrn 0;}
Chang ' An (YY ' s problem-matrix multiplication)