#line 1 "combined.cpp" #pragma region Macros #include using namespace std; // input output utils namespace siro53_io { // https://maspypy.github.io/library/other/io_old.hpp struct has_val_impl { template static auto check(T &&x) -> decltype(x.val(), std::true_type{}); template static auto check(...) -> std::false_type; }; template class has_val : public decltype(has_val_impl::check(std::declval())) { }; // debug template ::value, int> = 0> void dump(const T t) { cerr << t; } template ::value, int> = 0> void dump(const T t) { cerr << t; } template ::value>::type * = nullptr> void dump(const T &t) { cerr << t.val(); } void dump(__int128_t n) { if(n == 0) { cerr << '0'; return; } else if(n < 0) { cerr << '-'; n = -n; } string s; while(n > 0) { s += (char)('0' + n % 10); n /= 10; } reverse(s.begin(), s.end()); cerr << s; } void dump(const string &s) { cerr << s; } void dump(const char *s) { int n = (int)strlen(s); for(int i = 0; i < n; i++) cerr << s[i]; } template void dump(const pair &p) { cerr << '('; dump(p.first); cerr << ','; dump(p.second); cerr << ')'; } template void dump(const vector &v) { cerr << '{'; for(int i = 0; i < (int)v.size(); i++) { dump(v[i]); if(i < (int)v.size() - 1) cerr << ','; } cerr << '}'; } template void dump(const set &s) { cerr << '{'; for(auto it = s.begin(); it != s.end(); it++) { dump(*it); if(next(it) != s.end()) cerr << ','; } cerr << '}'; } template void dump(const map &mp) { cerr << '{'; for(auto it = mp.begin(); it != mp.end(); it++) { dump(*it); if(next(it) != mp.end()) cerr << ','; } cerr << '}'; } template void dump(const unordered_map &mp) { cerr << '{'; for(auto it = mp.begin(); it != mp.end(); it++) { dump(*it); if(next(it) != mp.end()) cerr << ','; } cerr << '}'; } template void dump(const deque &v) { cerr << '{'; for(int i = 0; i < (int)v.size(); i++) { dump(v[i]); if(i < (int)v.size() - 1) cerr << ','; } cerr << '}'; } template void dump(queue q) { cerr << '{'; while(!q.empty()) { dump(q.front()); if((int)q.size() > 1) cerr << ','; q.pop(); } cerr << '}'; } void debug_print() { cerr << endl; } template void debug_print(const Head &h, const Tail &...t) { dump(h); if(sizeof...(Tail)) dump(' '); debug_print(t...); } // print template ::value, int> = 0> void print_single(const T t) { cout << t; } template ::value, int> = 0> void print_single(const T t) { cout << t; } template ::value>::type * = nullptr> void print_single(const T t) { cout << t.val(); } void print_single(__int128_t n) { if(n == 0) { cout << '0'; return; } else if(n < 0) { cout << '-'; n = -n; } string s; while(n > 0) { s += (char)('0' + n % 10); n /= 10; } reverse(s.begin(), s.end()); cout << s; } void print_single(const string &s) { cout << s; } void print_single(const char *s) { int n = (int)strlen(s); for(int i = 0; i < n; i++) cout << s[i]; } template void print_single(const pair &p) { print_single(p.first); cout << ' '; print_single(p.second); } template void print_single(const vector &v) { for(int i = 0; i < (int)v.size(); i++) { print_single(v[i]); if(i < (int)v.size() - 1) cout << ' '; } } template void print_single(const set &s) { for(auto it = s.begin(); it != s.end(); it++) { print_single(*it); if(next(it) != s.end()) cout << ' '; } } template void print_single(const deque &v) { for(int i = 0; i < (int)v.size(); i++) { print_single(v[i]); if(i < (int)v.size() - 1) cout << ' '; } } template void print_single(queue q) { while(!q.empty()) { print_single(q.front()); if((int)q.size() > 1) cout << ' '; q.pop(); } } void print() { cout << '\n'; } template void print(const Head &h, const Tail &...t) { print_single(h); if(sizeof...(Tail)) print_single(' '); print(t...); } // input template ::value, int> = 0> void input_single(T &t) { cin >> t; } template ::value, int> = 0> void input_single(T &t) { cin >> t; } template ::value>::type * = nullptr> void input_single(T &t) { cin >> t; } void input_single(__int128_t &n) { string s; cin >> s; if(s == "0") { n = 0; return; } bool is_minus = false; if(s[0] == '-') { s = s.substr(1); is_minus = true; } n = 0; for(int i = 0; i < (int)s.size(); i++) n = n * 10 + (int)(s[i] - '0'); if(is_minus) n = -n; } void input_single(string &s) { cin >> s; } template void input_single(pair &p) { input_single(p.first); input_single(p.second); } template void input_single(vector &v) { for(auto &e : v) input_single(e); } void input() {} template void input(Head &h, Tail &...t) { input_single(h); input(t...); } }; // namespace siro53_io #ifdef DEBUG #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debug_print(__VA_ARGS__) #else #define debug(...) (void(0)) #endif // io setup struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using namespace siro53_io; // types using ll = long long; using i128 = __int128_t; // input macros #define INT(...) \ int __VA_ARGS__; \ input(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ input(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ input(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ input(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ input(__VA_ARGS__) #define LD(...) \ long double __VA_ARGS__; \ input(__VA_ARGS__) #define UINT(...) \ unsigned int __VA_ARGS__; \ input(__VA_ARGS__) #define ULL(...) \ unsigned long long __VA_ARGS__; \ input(__VA_ARGS__) #define VEC(name, type, len) \ vector name(len); \ input(name); #define VEC2(name, type, len1, len2) \ vector name(len1, vector(len2)); \ input(name); // other macros // https://trap.jp/post/1224/ #define OVERLOAD3(_1, _2, _3, name, ...) name #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define REP1(i, n) for(int i = 0; i < int(n); i++) #define REP2(i, a, b) for(int i = (a); i < int(b); i++) #define REP(...) OVERLOAD3(__VA_ARGS__, REP2, REP1)(__VA_ARGS__) #define SORT(v) sort(ALL(v)) #define RSORT(v) sort(RALL(v)) #define UNIQUE(v) \ sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()), v.shrink_to_fit() #define REV(v) reverse(ALL(v)) #define SZ(v) ((int)(v).size()) #define MIN(v) (*min_element(ALL(v))) #define MAX(v) (*max_element(ALL(v))) // util const const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; constexpr int MOD2 = 998244353; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; // util functions void Case(int i) { cout << "Case #" << i << ": "; } int popcnt(int x) { return __builtin_popcount(x); } int popcnt(ll x) { return __builtin_popcountll(x); } template inline bool chmax(T &a, T b) { return (a < b ? a = b, true : false); } template inline bool chmin(T &a, T b) { return (a > b ? a = b, true : false); } template auto make_vector_impl(vector& sizes, const T &e) { if constexpr(dim == 1) { return vector(sizes[0], e); } else { size_t n = sizes[dim - 1]; sizes.pop_back(); return vector(n, make_vector_impl(sizes, e)); } } template auto make_vector(const size_t (&sizes)[dim], const T &e) { vector s(dim); for(size_t i = 0; i < dim; i++) s[i] = sizes[dim - i - 1]; return make_vector_impl(s, e); } #pragma endregion Macros #line 2 "/Users/siro53/kyo-pro/compro_library/modint/modint.hpp" #line 6 "/Users/siro53/kyo-pro/compro_library/modint/modint.hpp" template class ModInt { public: ModInt() : x(0) {} ModInt(long long y) : x(y >= 0 ? y % umod() : (umod() - (-y) % umod()) % umod()) {} unsigned int val() const { return x; } ModInt &operator+=(const ModInt &p) { if((x += p.x) >= umod()) x -= umod(); return *this; } ModInt &operator-=(const ModInt &p) { if((x += umod() - p.x) >= umod()) x -= umod(); return *this; } ModInt &operator*=(const ModInt &p) { x = (unsigned int)(1ULL * x * p.x % umod()); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inv(); return *this; } ModInt operator-() const { return ModInt(-(long long)x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inv() const { long long a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; std::swap(a -= t * b, b); std::swap(u -= t * v, v); } return ModInt(u); } ModInt pow(unsigned long long n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend std::ostream &operator<<(std::ostream &os, const ModInt &p) { return os << p.x; } friend std::istream &operator>>(std::istream &is, ModInt &a) { long long t; is >> t; a = ModInt(t); return (is); } static constexpr int get_mod() { return mod; } private: unsigned int x; static constexpr unsigned int umod() { return mod; } }; #line 334 "combined.cpp" using mint = ModInt; #line 2 "/Users/siro53/kyo-pro/compro_library/math/binom.hpp" #line 6 "/Users/siro53/kyo-pro/compro_library/math/binom.hpp" template class Binomial { public: explicit Binomial(): Binomial(1) {} explicit Binomial(int MAX) : f(MAX, mint(1)), f_inv(MAX, mint(1)) { for(int i = 1; i < MAX; i++) f[i] = f[i-1] * mint(i); f_inv[MAX - 1] = f[MAX - 1].inv(); for(int i = MAX - 2; i >= 1; i--) { f_inv[i] = f_inv[i + 1] * mint(i + 1); } } void extend() { int n = (int)f.size(); f.resize(n * 2); f_inv.resize(n * 2); for(int i = n; i < n * 2; i++) f[i] = f[i - 1] * mint(i); f_inv[n * 2 - 1] = f[n * 2 - 1].inv(); for(int i = n * 2 - 2; i >= n; i--) { f_inv[i] = f_inv[i + 1] * mint(i + 1); } } mint fac(int n) { if(n < 0) return mint(0); while(n >= (int)f.size()) extend(); return f[n]; } mint fac_inv(int n) { if(n < 0) return mint(0); while(n >= (int)f_inv.size()) extend(); return f_inv[n]; } mint inv(int n) { if(n < 0) return -mint(-n); assert(n != 0); while(n >= (int)f_inv.size()) extend(); return (f_inv[n] * f[n - 1]); } mint binom(int n, int k) { if(n < k || n < 0 || k < 0) return mint(0); return (fac(n) * fac_inv(k) * fac_inv(n - k)); } mint binom_naive(long long n, long long k) { if(n < k || n < 0 || k < 0) return mint(0); mint res(1); k = std::min(k, n - k); for(int i = 0; i < k; i++) res *= inv(i + 1) * mint(n - i); return res; } mint perm(int n, int k) { if(n < k || n < 0 || k < 0) return mint(0); return (fac(n) * fac_inv(n - k)); } mint hom(int n, int k) { if(n < 0 || k < 0) return mint(0); return (k == 0 ? mint(1) : binom(n + k - 1, k)); } private: std::vector f, f_inv; }; #line 336 "combined.cpp" void solve() { INT(N, K); Binomial bi; mint ans = 0; REP(i, 1, N+1) { ans += mint((N - i) & 1 ? -1 : 1) * bi.binom(N, i) * mint(i).pow(K + N); } ans *= bi.fac_inv(N + K); print(ans / mint(N).pow(K) * bi.fac(K)); } int main() { int T{1}; // cin >> T; while(T--) solve(); }