/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include #include #ifndef SOLUTION_COMMON_H #include using namespace std; using ll = long long; using PI = pair; template using V = vector; using VI = V; #define _1 first #define _2 second #ifdef MY_DEBUG # define DEBUG(x) x #else # define DEBUG(x) #endif template inline void debug(T &A) { DEBUG( for (const auto &a : A) { cerr << a << " "; } cerr << '\n'; ) } template inline void debug_with_format(T &A, Func f) { DEBUG( for (const auto &a : A) { cerr << f(a) << " "; } cerr << '\n'; ) } template inline void debug_dim2(T &A) { DEBUG( for (const auto &as : A) { debug(as); } ) } template inline void debug(const char *format, Args const &... args) { DEBUG( fprintf(stderr, format, args ...); cerr << '\n'; ) } template string format(const string &fmt, Args ... args) { size_t len = snprintf(nullptr, 0, fmt.c_str(), args ...); vector buf(len + 1); snprintf(&buf[0], len + 1, fmt.c_str(), args ...); return string(&buf[0], &buf[0] + len); } template string fmtP(pair a) { stringstream ss; ss << "(" << a._1 << "," << a._2 << ")"; return ss.str(); } #define SOLUTION_COMMON_H #endif //SOLUTION_COMMON_H class Comb { public: int MOD; V F, I; Comb(int N, int MOD): MOD(MOD), F(N + 1), I(N + 1) { F[0] = 1; for (int i = 1; i <= N; ++i) { F[i] = F[i - 1] * i % MOD; } I[N] = pow_mod(F[N], MOD - 2, MOD); for (int i = N - 1; i >= 0; --i) { I[i] = I[i + 1] * (i + 1) % MOD; } } static ll pow_mod(ll x, int k, int MOD) { ll res = k >= 2 ? pow_mod(x * x % MOD, k / 2, MOD) : 1ll; if (k&1) res = res * x % MOD; return res; }; ll operator()(int n, int k) { if (k < 0 || k > n) return 0ll; return F[n] * I[n - k] % MOD * I[k] % MOD; }; ll rev(int x) { return F[x - 1] * I[x] % MOD; } }; const int MOD = 1000000007; inline void add(ll &a, ll b) { a += b; if (a >= MOD) a -= MOD; } inline void mul(ll &a, ll b) { a = a * b % MOD; } class B { public: void solve(std::istream& in, std::ostream& out) { int N, K; in >> N >> K; Comb comb(N + 1, MOD); ll ALL = comb.F[N]; comb(ALL, comb.I[K]); debug("ALL:%d", ALL); ll ans = 0ll; for (int i = 1; i <= N; ++i) { // i, i+1 どちらもあるケース ll a = 0ll; if (N != i) { a = comb(N - 2, K - 2); mul(a, comb.F[K]); mul(a, comb.rev(2)); } // iがないケース ll b = 0ll; if (N - 1 - K >= 0) { b = comb.F[N - 1]; mul(b, comb.I[max(0, N - 1 - K)]); } debug("i:%d a:%d b:%d", i, a, b); add(a, b); mul(a, i); add(ans, a); } out << ans; } }; int main() { B solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }