Check if it is possible to reach vector B by rotating vector A and adding vector C to it | function to check if vector B is possible from vector A ; if d = 0 , then you need to add nothing to vector A ; for all four quadrants ; initialize all three vector coordinates
def check ( a , b , p , q ) : NEW_LINE INDENT d = p * p + q * q ; NEW_LINE if ( d == 0 ) : NEW_LINE INDENT return a == 0 and b == 0 ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( ( a * p + b * q ) % d == 0 and ( b * p - a * q ) % d == 0 ) ; NEW_LINE DEDENT DEDENT def checks ( a , b , x , y , p , q ) : NEW_LINE INDENT if ( check ( a - x , b - y , p , q ) or check ( a + x , b + y , p , q ) or check ( a - y , b + x , p , q ) or check ( a + y , b - x , p , q ) ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT a = - 4 ; NEW_LINE b = - 2 ; NEW_LINE x = 0 ; NEW_LINE y = 0 ; NEW_LINE p = - 2 ; NEW_LINE q = - 1 ; NEW_LINE if ( checks ( a , b , x , y , p , q ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT