def max_factor(x: int, y: int) -> int:
    """
    Find the maximum `d` such that `x % d == 0` and `d <= y`.
    """
    if x <= y:
        return x

    result = 1
    for d in range(2, min(int(x**0.5), y) + 1):
        inv_d = x // d
        if inv_d * d == x:
            if inv_d <= y:
                return inv_d
            result = d

    return result