def simplify_mod_product(base: int, factor: int, value: int) -> int:
    """
    Assuming (factor * k) % base == value, return v such that k % base == v
    Also assumes that base is prime.
    There seem to be efficient ways to compute this result (https://en.wikipedia.org/wiki/Modular_arithmetic#Properties)
    but the numbers in this problem are relatively small so brute forcing it is fast enough.
    This function's big O runtime is linear to the magnitude of each base, which is several hundred.
    """
    return next(i for i in range(base) if factor * i % base == value)