BZOJ 5118

矩阵乘也是可以欧拉定理的HHH

所以幂次就是$(2^n-1) ~ mod ~ \varphi(p)$就好了

const ll p=1125899839733759ll;
inline ll mu(ll n,ll m,ll p){ll r=0;for(;m;m>>=1,n=(n+n)%p)if(m&1)r=(n+r)%p;return r;}
inline ll pw(ll n,ll m){ll r=1;for(;m;m>>=1,n=mu(n,n,p-1))if(m&1)r=mu(r,n,p-1);return r;}
#define prm(a) //{For(i,0,2)For(j,0,2)printf("%lld%c",(a)[i][j]," \n"[j==1]);}
template<int H>struct Matrix{
	ll a[H][H];Matrix(ll t=0){For(i,0,H)For(j,0,H)a[i][j]=(i!=j?0:t);}
	ll*operator[](const int&t){return a[t];}
	Matrix operator*(const Matrix&t)const{
		Matrix r;
		For(k,0,H)For(i,0,H)For(j,0,H)
			r[i][j]=(r[i][j]+mu(a[i][k],t.a[k][j],p))%p;
		return r;
	}
	Matrix operator^(ll k){Matrix r(1),n=*this;prm(r);for(;k;k>>=1,n=n*n)if(k&1)r=r*n;return r;}
};
Matrix<2>a;
int main(){
	int T;ll n;cin>>T;
	while(T--){
		cin>>n;
		n=pw(2ll,n)-1;
		a[0][0]=a[0][1]=a[1][0]=1,a[1][1]=0;
		a=a^(n);
		prm(a);
		cout<<a[0][0]<<endl;
	}
}

还有一个奇怪的操作:

$\sqrt{5}$ 在这个模数的意义下是存在的,所以直接带入 $f_n = \dfrac{\sqrt{5}}{5}[(\dfrac{\sqrt{5}+1}{2})^n+(\dfrac{1-\sqrt{5}}{5})^n]$

转载于:https://www.cnblogs.com/limfc/p/8385468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值