Check if it is possible to reach vector B by rotating vector A and adding vector C to it | C ++ program to Check if it is possible to reach vector B by Rotating vector A and adding vector C to it any number of times ; 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 ; Driver code ; initialize all three vector coordinates
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE ll check ( ll a , ll b , ll p , ll q ) { ll d = p * p + q * q ; if ( d == 0 ) return a == 0 && b == 0 ; else return ( a * p + b * q ) % d == 0 && ( b * p - a * q ) % d == 0 ; } bool check ( int a , int b , int x , int y , int p , int q ) { if ( check ( a - x , b - y , p , q ) || check ( a + x , b + y , p , q ) || check ( a - y , b + x , p , q ) || check ( a + y , b - x , p , q ) ) return true ; else return false ; } int main ( ) { int a = -4 , b = -2 ; int x = 0 , y = 0 ; int p = -2 , q = -1 ; if ( check ( a , b , x , y , p , q ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }