【杭电多校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;
}