/* http://projecteuler.net/
 *
 * Problem 15
 * Starting in the top left corner of a 2x2 grid, there are 6 routes
 * (without backtracking) to the bottom right corner. How many routes
 * are there through a 20x20 grid?
 *
 * Solution by Melkor (Filip Niksic, fniksic@gmail.com)
 *
 **/

#include <iostream>

using namespace std;

int main() {
    long long result = 1, n, k;

    cout << "Insert n, k: ";
    cin >> n >> k;

    // Calculating (n choose k)
    // To solve Problem 15, use n=40, k=20.

    if (k > n/2) k = n - k;

    for (long long i = n; i >= n - k + 1; --i) {
	result *= i;
	result /= n-i+1;
    }

    cout << "(n choose k) = " << result << endl;

    return 0;
}
