#include #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pi; typedef pair pl; typedef pair ppi; typedef vector vi; typedef vector vl; typedef vector mat; typedef complex comp; void Debug() {cerr << '\n'; } templatevoid Debug(FIRST arg, REST... rest){ cerr<ostream& operator<<(ostream& out,const vector& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<ostream& operator<<(ostream& out,const pair& v){ out<<"("<= b if(a < b || a < 0 || b < 0) return 0; return fac[a] * fiv[b] % mod * fiv[a - b] % mod; } int N, K; ll ans(int at, vector vec) { if(at == K) { int res = 0; rep(i, 1, N + 1) { if(vec[i]) res += i; } return res; } ll sum = 0; rep(i, 1, N + 1) { vector tmp = vec; tmp[i - 1] += tmp[i]; tmp[i] = 0; sum += ans(at + 1, tmp); } return sum; } ll dp[310][310][310]; ll loop(int a, int b, int k) { if(k == 0) { if(a == 0 && b == 1) return 1; else return 0; } if(dp[a][b][k] != -1) return dp[a][b][k]; ll res = 0; if(a > 0) { if(a < b - 1) ADD(res, loop(a, b - 1, k - 1) * inv[N] % mod); ADD(res, loop(a - 1, b, k - 1) * inv[N] % mod); ADD(res, loop(a, b, k - 1) * inv[N] % mod * (N - 2) % mod); } else { ADD(res, loop(a, b - 1, k - 1) * inv[N] % mod); ADD(res, loop(a, b, k - 1) * inv[N] % mod * (N - 1) % mod); } return dp[a][b][k] = res; } void solve() { cin >> N >> K; memset(dp, -1, sizeof(dp)); C_init(N); ll res = 0; ll base = mod_pow((N - 1) * inv[N] % mod, K); rep(i, 1, N + 1) { ll p = base; rep(j, 0, K + 1) { if(i + j + 1 > N) continue; ADD(p, loop(j + 1, j + 2, K)); } ADD(res, p * i % mod); } cout << res * mod_pow(N, K) % mod << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" :"=a"(res) ::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }