def combinations_exact(n, k):
    """Calculates combinations by integer division.

    Preferred method for small combinations, but slow on larger ones.

    Note: no error checking (expects to be called through combinations())
    """
    # permutations(n, k) = permutations(n, n-k), so reduce computation by
    # figuring out which requires calculation of fewer terms.
    if k > (n - k):
        larger = k
        smaller = n - k
    else:
        larger = n - k
        smaller = k

    product = 1
    # compute n!/(n-larger)! by multiplying terms from n to (n-larger+1)
    for i in range(larger + 1, n + 1):
        product *= i

    # divide by (smaller)! by multiplying terms from 2 to smaller
    for i in range(2, smaller + 1):  # no need to divide by 1...
        product /= i  # ok to use integer division: should always be factor

    return product