def get_ith_range(rng, idx, num):
    """
    Divide the full range `rng` into `num` parts, and get the `idx`-th range.
    """
    length = rng[1] - rng[0]
    beg = rng[0] + idx * length // num
    end = rng[0] + (idx + 1) * length // num
    assert end <= rng[1]
    return beg, end
