# UVALive 7040 (容斥)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <time.h>
#include <cmath>
using namespace std;
#define mod 1000000007
#define maxn 1111111

long long f[maxn];//逆元
void init(){
f[1] = 1;
for (int i = 2; i <= 1000000; i++){
f[i] = (long long)(mod - mod/i) * f[mod % i] % mod;
}
}

long long n, k, m;
long long c[maxn];

long long qpow (long long a, long long b) {
a %= mod;
if (b == 0)
return 1;
long long ans = qpow (a, b>>1);
ans = ans*ans%mod;
if (b&1)
ans = ans*a%mod;
return ans;
}

int main () {
init ();
int t, kase = 0;
scanf ("%d", &t);
while (t--) {
scanf ("%lld%lld%lld", &n, &m, &k);
printf ("Case #%d: ", ++kase);
if (k == 1 && n == 1) {
printf ("%lld\n", m);
continue;
}
if (k == 1 && n > 1) {
printf ("0\n");
continue;
}
long long ans = m%mod;
for (long long i = 2; i <= k; i++) {
ans = ans*(m-i+1)%mod*f[i]%mod;
}
c[1] = k%mod;
for (long long i = 2; i <= k; i++) {
c[i] = c[i-1]*(k-i+1)%mod*f[i]%mod;
}
long long res = k*qpow (k-1, n-1) % mod;
for (long long i = 1; i < k; i++) {
long long id = ((i&1) ? -1 : 1);
long long cur = c[i]*(k-i)%mod*qpow (k-i-1, n-1)%mod;
cur *= id;
if (cur < 0)
cur += mod;
res += cur;
res %= mod;
}
printf ("%lld\n", ans*res%mod);
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120