#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% import numpy as np # %% N, K = map(int, read().split()) # %% MOD = 10**9 + 7 # %% def cumprod(A, MOD=MOD): L = len(A) Lsq = int(L**.5 + 1) A = np.resize(A, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): A[:, n] *= A[:, n - 1] A[:, n] %= MOD for n in range(1, Lsq): A[n] *= A[n - 1, -1] A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD=MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact, fact_inv # %% fact, fact_inv = make_fact(10**5 + 100) inv = np.zeros_like(fact) inv[1:] = fact[:-1] * fact_inv[1:] % MOD # %% inv = inv.astype(object) p_N = (N - K) * inv[N] p = p_N + (K * (K - 1)) * inv[N] * inv[N - 1] * inv[2] expected = (N - 1) * N // 2 * p + N * p_N perm = int(fact[N] * fact_inv[N - K]) answer = expected * perm % MOD print(answer)