#include //sort,二分探索,など #include //popcount #include //固定長bit集合 #include //pow,logなど #include //複素数 #include //両端アクセスのキュー #include //ファイルストリーム(標準入力変更用) #include //sortのgreater #include //setprecision(浮動小数点の出力の誤差) #include //入出力 #include //集合演算(積集合,和集合,差集合など) #include //map(辞書) #include //iota(整数列の生成),gcdとlcm(c++17) #include //キュー #include //集合 #include //スタック #include //文字列 #include //イテレータあるけど順序保持しないmap #include //イテレータあるけど順序保持しないset #include //pair #include //可変長配列 //#include //using namespace atcoder; //名前 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef map msi; typedef map msll; typedef pair pii; typedef pair pllll; typedef vector vi; typedef vector vll; typedef vector vs; typedef vector vb; typedef vector> vvi; typedef vector> vvll; typedef vector> vvs; typedef vector> vvb; //定数 const ll MOD = 1000000007; const ll INF = 1000000000000000000; const int MAXR = 100000; //10^5:配列の最大のrange //マクロ #define rep(i,n) for(int i=0;i=0;i--) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define in1(x1) cin >> x1 #define in2(x1, x2) cin >> x1 >> x2 #define in3(x1, x2, x3) cin >> x1 >> x2 >> x3 #define in4(x1, x2, x3, x4) cin >> x1 >> x2 >> x3 >> x4 #define in5(x1, x2, x3, x4, x5) cin >> x1 >> x2 >> x3 >> x4 >> x5 #define in6(x1, x2, x3, x4, x5, x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6 #define inN(x, N) rep(i, N) in1(x[i]) #define outl(x) cout << x << endl #define out2l(x, y) cout << x << " " << y << endl #define out4l(x1, x2, x3, x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << endl #define outList(x) for(auto y : x) cout << y << " ";cout << endl //よく使う関数 template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } inline ll div_ceil(ll a, ll b) { return (a + (b - 1)) / b; } ll combination(int n, int r) { //nCr = nC(n-r)を使用して計算量を節約 if (n - r < r) r = n - r; //自明な場合の戻り値 if (r == 0) return 1; if (r == 1) return n; //組み合わせの数の定義に登場する分母・分子の要素 vector numerator(r, 0); vector denominator(r, 0); //初期化 rep(k, r) { numerator[k] = n - r + k + 1; denominator[k] = k + 1; } //分子を分母で割っていく。 repse(p, 2, r) { int pivot = denominator[p - 1]; if (pivot > 1) { int offset = (n - r) % p; for (int k = p - 1; k < r; k += p) { //分子は割り切れる場所までスライド numerator[k - offset] /= pivot; denominator[k] /= pivot; } } } ll result = 1; rep(k, r) { //残りを全部乗算 if (numerator[k] > 1) result *= numerator[k]; } return result; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //標準入力をファイルに変更 //std::ifstream in("input.txt"); //std::cin.rdbuf(in.rdbuf()); int N, K; in2(N, K); ll ans = 0; if (K == 1) { //先頭に1を入れる repse(i, 1, N - 2) { ans += combination(N - 1, i) - 1; } } else { //先頭以外に1を入れる repse(i, 0, N - K) { ans += combination(N - K, i); } } outl(ans); return 0; }