#include<bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

int N, K;
int64 fact[101];
int64 dp[101][100001];

int rec(int idx, int add)
{
  if(idx == 0) return (0);
  if(~dp[idx][add]) return (dp[idx][add]);
  long long ret = 0;
  for(int i = 0; i <= K; i++) {
    if(i <= idx && idx <= add + i) {
      int sqr = (add + i) % idx;
      (ret += 1LL * fact[idx - 1] * sqr % mod) % mod;
      (ret += rec(idx - 1, add + (add + i) / idx)) %= mod;
    } else {
      (ret += 1LL * fact[idx - 1] * (i + add) % mod) %= mod;
      (ret += rec(idx - 1, add)) %= mod;
    }
  }
  return (dp[idx][add] = ret);
}

int main()
{
  cin >> N >> K;
  fact[0] = 1;
  for(int i = 1; i <= N; i++) {
    (fact[i] = fact[i - 1] * (K + 1)) %= mod;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(N, 0) << endl;
}