func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long mod = 1000 * 1000 * 1000 + 7;   long long n, k;   vector<long long> ans;   long long positive(long long n) {     n %= mod;     (n < 0) && (n += mod);     return n;   }   long long gcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long g = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return g;   }   long long binpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   void calc() {     long long x = 0;     ans.push_back(0);     for (int i = 0; i < k + 1; ++i) {       x = (x + binpow(i + 1, k)) % mod;       ans.push_back(x);     }   }   long long solve(vector<long long> ans, long long y) {     long long x = 0;     long long cur = 1;     for (int j = 1; j < (long long)ans.size(); ++j) {       cur = (cur * positive(y - j)) % mod;       cur = (cur * binpow(positive(0 - j), mod - 2)) % mod;     }     for (int i = 0; i < (long long)ans.size(); ++i) {       x = (x + (ans[i] * cur) % mod) % mod;       if (i + 1 >= (long long)ans.size()) break;       long long t =           (positive(y - i) * binpow(positive(y - (i + 1)), mod - 2)) % mod;       cur = (cur * t) % mod;       long long v = (positive(i - ((long long)ans.size() - 1)) *                      binpow(positive(i + 1), mod - 2)) %                     mod;       cur = (cur * v) % mod;     }     return x;   }   int main() {     cin >> n >> k;     calc();     if (n < ans.size()) {       cout << ans[n];     } else {       cout << solve(ans, n);     }   }   