思路:
我们直接算出g(x),然后发现就是一道组合数学
记得要高精
c o d e code code
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
ll n, k;
ll a[10001];
ll qpow(ll x, ll k, ll mod) {
ll ans = 1;
for(; k; k >>= 1, x = x * x % mod) if(k & 1) ans = ans * x % mod;
return ans;
}
void cheng(ll x) {
ll g = 0;
for(ll i = 10000; i >= 1; i --) {
a[i] = a[i] * x + g;
g = a[i] / 10;
a[i] %= 10;
}
}
void chu(ll x) {
ll g = 0;
for(ll i = 1; i <= 10000; i ++) {
ll p = (g * 10 + a[i]) % x;
a[i] = (g * 10 + a[i]) / x;
g = p;
}
}
// n! / m!(n-m)!
void C(ll n, ll m) {
a[10000] = 1;
for(ll i = m + 1; i <= n; i ++) cheng(i);
for(ll i = 2; i <= n - m; i ++) chu(i);
}
void write_() {
ll i = 1;
while(a[i] == 0 && i + 1 <= 10000) i ++;
while(i <= 10000) printf("%lld", a[i]), i ++;
}
int main() {
scanf("%lld%lld", &k, &n);
ll m = qpow(n, n, 1000);
C(m - 1, k - 1);
write_();
return 0;
}