题解:一个图的K次方相当于 i走k步到j这个点。于是走过的点有i,j1,j2....jk。其中jk为最后的终点。根据卢卡斯定理:i>=j1>=j2....>=jk。所以这相当于隔板法从p个元素中选j+1个可重复的元素。即C(j+p,j+1) = C(j+p,p-1)。且P进制中每一位是单独考虑的。
所以有
注意事项:后面等差数列有a-1做逆元的,有a-1 = 0的情况要特殊考虑!!
#include"bits/stdc++.h"
using namespace std;
typedef long long LL;
const int MX = 13e5+7;
const int mod = 1e9+7;
int prime[MX],tt;
bool no_prime[MX];
LL inv[MX],fac[MX];
LL qpow(LL a, LL n, LL mod)
{
LL ret = 1;
a %= mod;
while(n)
{
if(n&1) ret = ret*a%mod;
a = a*a%mod;
n >>= 1;
}
return ret;
}
void init()
{
int n = MX - 7;
for(int i = 2; i <= n; i++){
if(!no_prime[i]) prime[++tt] = i;
for(int j = 1; j <= tt && i*prime[j] <= n; j++){
no_prime[i*prime[j]] = 1;
if(!i%prime[j]) break;
}
}
int p = prime[100000];
fac[0] = fac[1] = inv[0] = inv[1] = 1;
for(int i = 2; i <= p; i++) fac[i] = fac[i-1]*i%mod;
inv[p] = qpow(fac[p],mod-2,mod);
for(int i = p; i > 2; i--) inv[i-1] = inv[i]*i%mod;
}
void solve()
{
int c,n,k;
scanf("%d%d%d",&c,&n,&k);
assert( n > 0 && n <= 1000000000 && c > 0 && c <= 100000 && k > 0 && k <= 100000);
LL p = prime[c];
LL f = fac[p], ans = 0;
for(int j = 1; j <= k; j++){
f = f*(p+j)%mod;
LL a = f*inv[p-1]%mod*inv[j+1]%mod;
//除数为0的逆元要单独考虑
if(a > 1) ans = ((ans + (qpow(a,n+1,mod) - a+mod) *qpow(a-1,mod-2,mod)) )%mod;
else ans = (ans+n)%mod;
}
cout<<ans<<endl;
}
int main()
{
init();
int T;
for(scanf("%d",&T); T; T--)
solve();
}