标签:span long turn ring ace stream struct str cout
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define ll long long 6 const int MOD=30013; 7 using namespace std; 8 struct arr{ 9 ll p[2][2]; 10 arr(){ 11 for(int i=0;i<=1;++i) 12 for(int j=0;j<=1;++j) 13 p[i][j]=0; 14 } 15 }; 16 arr mul(arr a,arr b){ 17 arr c; 18 for(int i=0;i<=1;++i) 19 for(int j=0;j<=1;++j) 20 for(int k=0;k<=1;++k) 21 c.p[i][j]=(c.p[i][j]+a.p[i][k]*b.p[k][j])%MOD; 22 return c; 23 } 24 arr ksm(arr a,ll b){ 25 arr ret; ret.p[0][0]=ret.p[1][1]=1; 26 while(b){ 27 if(b&1) ret=mul(ret,a); 28 a=mul(a,a); 29 b>>=1; 30 } 31 return ret; 32 } 33 ll a,b,n; 34 int main() 35 { 36 cin>>a>>b>>n; 37 arr aha; aha.p[1][0]=b; 38 aha.p[0][0]=a;aha.p[0][1]=1; 39 aha=ksm(aha,n-2); 40 arr ba;ba.p[0][0]=1; ba.p[0][1]=1; 41 aha=mul(ba,aha); 42 cout<<aha.p[0][0]<<endl; 43 }
标签:span long turn ring ace stream struct str cout
原文地址:https://www.cnblogs.com/saionjisekai/p/9594588.html