1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7ll;
int T;
LL n, m, k;
LL jc[maxn], jcn[maxn];
inline LL mpow(LL a, LL b)
{
LL ret = 1, tem = a;
while (b)
{
if (b & 1)
ret = ret * tem % mod;
tem = tem * tem % mod;
b >>= 1;
}
return ret;
}
inline LL c(LL a, LL b)
{
return jc[a] * jcn[b] % mod * jcn[a - b] % mod;
}
void init()
{
jc[1] = jc[0] = 1;
jcn[1] = jcn[0] = 1;
for (int i = 2; i <= 1000000; i++)
jc[i] = jc[i - 1] * i % mod, jcn[i] = mpow(jc[i], mod - 2);
}
LL Pow(LL a, LL k)
{
if (k == 0)
return 1ll;
LL now = Pow(a, k / 2);
now = now * now % mod;
if (k % 2 == 1)
now = now * a % mod;
return now;
}
LL made(LL p, LL q)
{
LL now = p * Pow(p - 1, n - 1) % mod * c(k, q) % mod;
return now;
}
LL cc(LL m, LL k)
{
LL now = 1ll;
for (LL i = m; i >= m - k + 1; i--)
now = now * i % mod;
now = now * jcn[k] % mod;
return now;
}
int main()
{
scanf("%d", &T);
init();
for (int t = 1; t <= T; t++)
{
scanf("%lld%lld%lld", &n, &m, &k);
LL d = 1ll, s = 0, ans = 0;
for (LL i = k; i >= 1; i--)
{
LL now = made(i, s);
ans = (ans + d * now % mod + mod) % mod;
d = d * (-1ll);
s++;
}
ans = ans * cc(m, k) % mod;
printf("Case #%d: %lld\n", t, ans);
}
return 0;
}
|