import math


def gen_bins(minbin, maxbins, maxt):
    """Generate a list of bins with the given constraints:
       Bin size must be a multiple of minbin, with no more than maxbins in total,
       to cover possible values up to maxt.
       Return the size of the bins and a list of labels.
    """
    # First divide maxt by the max number of bins, then round the result up to
    # a multiple of minbin to get the required size.
    bin_size = math.ceil(maxt / (maxbins * minbin)) * minbin

    # Now see how many bins are actually needed at this size
    num_bins = math.ceil(maxt / bin_size)

    # Given that the units are in seconds we can generate labels in the form
    # 'HH:MM'
    bin_labels = []
    if (bin_size % 60) == 0:
        for c in range(num_bins):
            bin_labels.append( "{:02d}:{:02d}".format(
                                     (c * bin_size) // ( 60 * 60),
                                     (c * bin_size) %  ( 60 * 60) // 60 ) )
    else:
        # Eh? If you insist.
        for c in range(num_bins):
            bin_labels.append(str(c*bin_size))

    return bin_size, bin_labels