Fibonacci Sum
斐 波 那 契 通 项 有 a n = 1 5 ( ( 1 + 5 2 ) n − ( 1 − 5 2 ) n ) ( 1 5 ) k ∑ i = 0 n ( ( 1 + 5 2 ) i c − ( 1 − 5 2 ) i c ) k A = 1 + 5 2 , B = 1 − 5 2 ( 1 5 ) k ∑ i = 0 n ∑ j = 0 k ( − 1 ) k − j C k j A i c j B i c ( k − j ) ( 1 5 ) k ∑ j = 0 k ( − 1 ) k − j C k j ( ∑ i = 0 n A c j × i B c ( k − j ) × i ) 斐波那契通项有a_n = \frac{1}{\sqrt 5}\left((\frac{1 + \sqrt 5}{2}) ^ n - (\frac{1 - \sqrt 5}{2}) ^ n\right)\\ (\frac{1}{\sqrt 5}) ^ k \sum_{i = 0} ^ {n} \left((\frac{1 + \sqrt 5}{2}) ^{ic} - (\frac{1 - \sqrt 5}{2}) ^{ic} \right) ^ k\\ A = \frac{1 + \sqrt 5}{2}, B = \frac{1 - \sqrt 5}{2}\\ (\frac{1}{\sqrt 5}) ^ k\sum_{i = 0} ^{n} \sum_{j = 0} ^{k}(-1) ^{k - j} C_k ^ j A ^{icj} B^{ic(k - j)}\\ (\frac{1}{\sqrt 5}) ^ k\sum_{j = 0} ^{k}(-1) ^{k - j} C_{k} ^{j} \left(\sum_{i = 0} ^{n} A^{cj \times i} B ^{c(k - j) \times i} \right)\\ 斐波那契通项有an=51((21+5)n−(21−5)n)(51)ki=0∑n((21+5)ic−(21−5)ic)kA=21+5,B=21−5(51)ki=0∑nj=0∑k(−1)k−jCkjAicjBic(k−j)(51)kj=0∑k(−1)k−jCkj(i=0∑nAcj×iBc(k−j)×i)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 9, Mod = 1e9 + 8;
ll n, c, k;
const ll sqrt5 = 383008016, A = 691504013, B = 308495997;
const int N = 1e6 + 10;
ll quick_pow(ll a, ll n) {
ll ans = 1;
while (n) {
if (n & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return ans;
}
int fac[N], inv[N];
int C(int n, int m) {
if(n < 0 || m < 0 || m > n) return 0;
if(m == 0 || m == n) return 1;
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void init() {
fac[0] = 1;
for(int i = 1; i < N; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
inv[N - 1] = quick_pow(fac[N - 1], mod - 2);
for(int i = N - 2; i >= 0; i--)
inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const ll inv_sqrt5 = quick_pow(sqrt5, mod - 2);
init();
int T;
scanf("%d", &T);
while (T--) {
scanf("%lld %lld %lld", &n, &c, &k);
ll A_C = quick_pow(A, c % Mod), B_C = quick_pow(B, c % Mod);
ll inv_B_C = quick_pow(B_C, mod - 2), base = quick_pow(B_C, k);
ll multi = A_C * inv_B_C % mod, ans = 0;
for (int i = 0; i <= k; i++){
ll temp;
if (base == 1){
temp = n % mod;
}
else {
temp = base * (quick_pow(base, n % Mod) + Mod) % mod * quick_pow(base - 1, mod - 2) % mod;
}
ll temp2 = C(k, i) * temp % mod;
if ((k - i) & 1){
ans = (ans - temp2 + mod) % mod;
}
else{
ans = (ans + temp2) % mod;
}
base = base * multi % mod;
}
ans = ans * quick_pow(inv_sqrt5, k) % mod;
printf("%lld\n", ans);
}
return 0;
}