Check if it is possible to reach vector B by rotating vector A and adding vector C to it | Java 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
public class GFG { static boolean check ( long a , long b , long p , long q ) { long 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 ; } static boolean 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 ; } public static void main ( String args [ ] ) { int a = - 4 , b = - 2 ; int x = 0 , y = 0 ; int p = - 2 , q = - 1 ; if ( check ( a , b , x , y , p , q ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }