import sys input = sys.stdin.readline N, S = map(int, input().split()) class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) self.el = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j = None): if j is None: return self.el[i] return self.sum(j) - self.sum(i) def lowerbound(self, s): x = 0 y = 0 for i in range(self.n.bit_length(), -1, -1): k = x + (1 << i) if k <= self.n and (y + self.data[k] < s): y += self.data[k] x += 1 << i return x + 1 class numeroBIT: def __init__(self, mx): self.mx = mx self.fwk = BIT(mx) def add(self, x): self.fwk.add(x, 1) def discard(self, x): if self.fwk.get(x): self.fwk.add(x, -1) def kthmax(self, k): n = self.fwk.sum(self.mx) return self.fwk.lowerbound(n - k + 1) nfwk = numeroBIT(S) for x in range(1, S + 1): nfwk.add(x) f = 1 for i in range(1, S): f *= i a = [] for i in range(S - 1, -1, -1): x = nfwk.kthmax(i + 1 - N // f) nfwk.discard(x) a.append(x) N %= f if i: f //= i #print(a) b = [] for i in range(S): for j in range(S): if i + 1 == a[j]: b.append(j + 1) break #print(b) for x in range(1, S + 1): nfwk.add(x) for i in range(1, S): f *= i res = 0 for i in range(S): x = b[i] y = nfwk.fwk.sum(x) - 1 res += y * f nfwk.discard(x) if S - i - 1: f //= (S - i - 1) print(res)