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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Fibonacci Sum HDU - 6755【2020 Multi-University Training Contest 1】斐波那契数列变形+二项式定理

發(fā)布時間:2023/12/4 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Fibonacci Sum HDU - 6755【2020 Multi-University Training Contest 1】斐波那契数列变形+二项式定理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

【杭電多校2020】Distinct Sub-palindromes
分析:

題目:

The Fibonacci numbers are defined as below:

Given three integers N, C and K, calculate the following summation:

Since the answer can be huge, output it modulo 1000000009 (10910^9109+9).

Input

The first line contains an integer T (1≤T≤200), denoting the number of test cases. Each test case contains three space separated integers in the order: N, C, K (1≤N,C≤101810^{18}1018,1≤K≤10510^5105).

Output

For each test case, output a single line containing the answer.

Sample Input

2
5 1 1
2 1 2

Sample Output

12
2
官方題解:

分析:

AC代碼:

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod=1e9+9; const int M=1e5; int pow_mod(int x,int i) {int y=1;while(i){if(i&1)y=(ll)y*x%mod;x=(ll)x*x%mod;i>>=1;}return y; } ll N,C; int K,a[M+5],b[M+5]; int comb(int n,int k) {if(n<k)return 0;return (ll)a[n]*b[k]%mod*b[n-k]%mod; } int main() {ios::sync_with_stdio(0);a[0]=1;for(int i=1; i<=M; ++i)a[i]=(ll)a[i-1]*i%mod;b[M]=pow_mod(a[M],mod-2);for(int i=M-1; i>=0; --i)b[i]=(ll)(i+1)*b[i+1]%mod;int T;cin>>T;while(T--){cin>>N>>C>>K;int A=691504013,B=308495997;A=pow_mod(A,C%(mod-1));B=pow_mod(B,C%(mod-1));int a=1,b=pow_mod(B,K);int ib=pow_mod(B,mod-2);int ans=0;for(int j=0; j<=K; ++j){int x=(ll)a*b%mod;if(x==1)x=(N+1)%mod;elsex=(ll)(pow_mod(x,(N+1)%(mod-1))-1+mod)%mod * pow_mod((x-1+mod)%mod,mod-2) % mod;if((K-j)&1)x=(x==0?x:mod-x);ans=((ll)ans+(ll)comb(K,j)*x)%mod;a=(ll)a*A%mod;b=(ll)b*ib%mod;}int mul=276601605;mul=pow_mod(mul,K);ans=(ll)ans*mul%mod;cout<<ans<<endl;}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Fibonacci Sum HDU - 6755【2020 Multi-University Training Contest 1】斐波那契数列变形+二项式定理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。