日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

E. Product Oriented Recurrence(codeforces R566 div2)

發布時間:2023/12/20 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 E. Product Oriented Recurrence(codeforces R566 div2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 矩陣快速冪+歐拉降冪

思路:

#include<bits/stdc++.h> using namespace std;typedef long long ll;ll mod=1e9+7;ll fp(ll x,ll y){//快速冪 ll ret=1;while(y){if(y&1)ret=ret*x%mod; x=x*x%mod;y/=2;}return ret; }int N=3;//矩陣大小 struct matrix{ll t[5][5]; }rela;ll t[5][5]={0,0,1,0,0,1,0,1,0,0,0,1,1,0,0, };//f的冪關系矩陣 ll tc[5][5]={1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,2,0,0,1,0,2,0,0,1,1 };//c冪的關系矩陣 //遞推關系是C(n+1)=C(n)+C(n-1)+C(n-2)+2*(n+1) matrix mul(matrix x,matrix y){//矩陣乘 matrix ans; for(int i=0;i<N;i++)for(int j=0;j<N;j++){ans.t[i][j]=0;for(int k=0;k<N;k++){ans.t[i][j]+=x.t[i][k]*y.t[k][j]%mod;ans.t[i][j]%=mod;} }return ans; }matrix fpow(matrix x,ll y){//矩陣快速冪 matrix ret;memset(ret.t,0,sizeof(ret));for(int i=0;i<N;i++)ret.t[i][i]=1; while(y){if(y&1)ret=mul(ret,x);x=mul(x,x); y>>=1;}return ret; }int main(){ios::sync_with_stdio(false);ll n,c,f[3],C_mi;cin>>n>>f[0]>>f[1]>>f[2]>>c;n-=3; ll ans=1;matrix a; mod--;//歐拉(費馬)降冪 memcpy(rela.t,t,sizeof(t));a=fpow(rela,n);mod++;for(int i=0;i<3;i++)//分別用不同的初始矩陣求f1,f2,f3的冪 ans=ans*fp(f[i],a.t[i][2])%mod;//f(n)=f(n-1)+f(n-2)+f(n-3)if(n==1)C_mi=2;else if(n==2)C_mi=6;else if(n==3)C_mi=14;else {ll init[5]={14,6,2,3,1};//Cn,Cn-1,Cn-2,n,1 n-=3,N=5;mod--;歐拉(費馬)降冪,之前寫錯位置了..調半天bug memcpy(rela.t,tc,sizeof(tc)); a=fpow(rela,n);C_mi=0;//之前寫在這 for(int i=0;i<5;i++){C_mi+=init[i]*a.t[i][0]%mod;C_mi%=mod; }mod++; } ans=ans*fp(c,C_mi)%mod; cout<<ans<<endl; }

總結

以上是生活随笔為你收集整理的E. Product Oriented Recurrence(codeforces R566 div2)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。