def representative_in_range(quotient_class, valid_range):
    """
    Return the unique representative of @p quotient_class in @p valid_range.
    For example, the representative of @c (3 mod 7) in @c range(13, 19) is 17.

    @param     quotient_class  A QuotientClass over the Integers.
    @param     valid_range     The range() object describing the interval in
                               which to the returned representative must lie. 

    @return    An integer @c x in @p valid_range with @c x % m == r, where
               @c m is the modulus, and @c r the remainder of @p quotient_class.  

    @exception ValueError  either if there is no representative in
                           @p valid_range, or if there are multiple.
    """
    if len(valid_range) > quotient_class.modulus():
        raise ValueError('solution not unique')
    q, r = divmod(valid_range[0], quotient_class.modulus())
    shifted_range = range(r, r + len(valid_range))
    if quotient_class.remainder() in shifted_range:
        return q * quotient_class.modulus() + quotient_class.remainder()
    elif quotient_class.remainder() + quotient_class.modulus(
        ) in shifted_range:
        return (q + 1) * quotient_class.modulus() + quotient_class.remainder()
    else:
        raise ValueError('no solution')
