标签:题意 lazy sdn 斐波那契数列 lse fine max scanf getc
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6755
题意:求一个式子,其中F是斐波那契数列
思路:因为斐波那契数列的通式为
所以式子可以化简为
又根据2mod 1e9+9的逆元为500000005,所以x^2≡5(mod 1e9+9)解得x为383008016
所以a≡(1+sqrt(5))/2≡(1+383008016)*500000005≡691504013(mod 1e9+9)
同理b≡308495997(mod 1e9+9)。
详细的链接在这:https://blog.csdn.net/acdreamers/article/details/23039571
#include<bits/stdc++.h> using namespace std; #define ll long long const ll mod=1e9+9; const ll MAXN=1e5; ll factor[MAXN+10]; ll invFactor[MAXN+10]; ll invn[MAXN+10]; const ll A=691504013; const ll invA=691504012; const ll B=308495997; const ll D=276601605; inline ll quick_pow(ll a, ll b) { ll ans=1, base=a; while(b!=0) { if (b&1) ans=(ll) ans*base%mod; base=(ll) base*base%mod; b>>=1; } return ans; } inline ll MOD(ll a, ll b) { a+=b; if (a>=mod) a-=mod; return a; } inline void init() { factor[0]=invFactor[0]=invn[0]=factor[1]=invFactor[1]=invn[1]=1; for(int i=2; i<=MAXN; i++) { factor[i]=factor[i-1]*i%mod; invn[i]=(ll) (mod-mod/i)*invn[mod%i]%mod; invFactor[i]=invFactor[i-1]*invn[i]%mod; } } inline ll getC(ll m, ll n) { if (n<0 || m<0 || m>n) return 0; ll ans=factor[n]; ans=(ll) ans*invFactor[m]%mod; ans=(ll) ans*invFactor[n-m]%mod; return ans; } int main() { init(); int t; scanf("%d", &t); while(t--) { ll n, c, k; scanf("%lld%lld%lld", &n, &c, &k); ll ans=0; ll a1=quick_pow(quick_pow(A, k), c%(mod-1)); ll q=quick_pow((ll) invA*B%mod, c%(mod-1)); ll n1=n%mod; ll n2=n%(mod-1); ll a1power=quick_pow(a1, n2); ll qpower=quick_pow(q, n2); for(int i=0; i<=k; i++) { ll sum=getC(i, k); if (i&1) { sum=mod-sum; } if (a1==1) { ans=(ans+(ll) sum*n1%mod)%mod; } else { sum=(ll) sum*((ll) a1*(a1power-1+mod)%mod)%mod; sum=(ll) sum*quick_pow(a1-1, mod-2)%mod; ans=MOD(ans, sum); } a1=(ll)a1*q%mod; a1power=(ll)a1power*qpower%mod; } printf("%lld\n",(ll)ans*quick_pow(D,k)%mod); } }
2020杭电多校第一场 1005.Fibonacci Sum
标签:题意 lazy sdn 斐波那契数列 lse fine max scanf getc
原文地址:https://www.cnblogs.com/2462478392Lee/p/13374145.html