def max_quantity(remain, coin, qty):
    """
    Calculate max quantity of a coin type to give change
    """
    max_qty = 0
    while remain >= coin and qty - max_qty > 0:
        remain = remain-coin
        max_qty += 1
    return max_qty