题目:https://codeforces.com/contest/1182/problem/E
分析:一道矩阵快速幂的题,关键是要两边取对数,再构造矩阵。
两边取对数:
令g[i]=,则g[i]=g[i-1]+g[i-2]+g[i-3]+2*i-6,从而可以构造出矩阵。
最后再取幂还原就行了
Ac code:
#include<cstdio>
#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
ll f1,f2,f3,n,c;
void muti(ll a[][5], ll b[][5]) {
ll tmp[5][5] = {0};
for (int i = 0; i <5; i++)
for (int j = 0; j <5; j++)
for (int k = 0; k <5; k++)
tmp[i][j] = (tmp[i][j]+ a[i][k] * b[k][j] ) % (mod-1);///由于是答案的幂,取模时需取mod的欧拉函数
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
a[i][j] = tmp[i][j];
}
ll quickpow(ll a,ll b)
{
ll ans=1,base=a;
while(b){
if(b&1)
ans=(ans*base)%mod;
base=(base*base)%mod;
b>>=1;
}
return ans;
}
ll Pow(ll n)
{
ll ans[5][5]={0};
ans[1][1]=ans[2][2]=ans[3][3]=ans[4][4]=ans[0][0]=1;
ll res[5][5]={0};
res[0][0]=res[0][1]=res[0][2]=res[0][3]=res[1][0]=res[2][1]=res[3][3]=res[3][4]=res[4][4]=1;
while(n){
if(n&1)
muti(ans,res);
muti(res,res);
n>>=1;
}
ll x=quickpow(f3,ans[0][0]);
x=(x*quickpow(f2,ans[0][1]))%mod;
x=(x*quickpow(f1,ans[0][2]))%mod;
x=(x*quickpow(c,2*(ans[0][3]+ans[0][4])))%mod;
return x;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>f1>>f2>>f3>>c;
ll y=Pow(n-3);
cout<<y<<endl;
return 0;
}