#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const ll INF=1000000000000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const ll M = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret;
	ret %= M;
	if(k%2 == 1){
		ret *= x;
		ret %= M;
	}
	return ret;
}

int main(){
	ll n,k;
	cin >> n >> k;
	
	static ll dp[102][5060] = {};
	dp[k][0] = k;
	dp[k][1] = 1;
	for(int i = k-1 ; i >= 1 ; i --){
		for(int j = 0 ; j < 5060 ; j ++){
			dp[i][j] += dp[i+1][j]*(k-i);
			dp[i][j+j/i] += dp[i+1][j]*(i-j%i);
			dp[i][j+j/i+1] += dp[i+1][j]*(j%i+1);
		}
		for(int j = 0 ; j < 5060 ; j ++){
			dp[i][j] %= M;
		}
	}
	
	ll ret = modpow(k+1,k)*n*k; ret %= M;
	ret *= modpow(2,M-2); ret %= M;
	rep1(i,5059){
		dp[1][i] *= i;
		dp[1][i] %= M;
		ret += M-dp[1][i];
	}
	ret %= M;
	ret *= modpow(k+1,n-k);
	cout << ret%M << endl;
}
	

