At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
- Turn the vector by 90 degrees clockwise.
- Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
Can Gerald cope with the task?
Input
The first line contains integers x1 и y1 — the coordinates of the vector A ( - 108 ≤ x1, y1 ≤ 108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).
Output
Print "YES" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print "NO" (without the quotes).
Examples
input
Copy
0 0
1 1
0 1
output
Copy
YES
input
Copy
0 0
1 1
1 1
output
Copy
YES
input
Copy
0 0
1 1
2 2
output
Copy
NO
/*
A向量可以在任意时间转动90度
相当于A向量可以在任意时间加上C向量或C转动90度或180或270度的
可以令四个C向量为 C1(x, y),C2(-x, -y),C3(y, -x),C4(-y, x)
-> A + a*C1 + b*C2 + c*C3 + d*C4 = Bi
-> x1 + x*(a-b) + y*(c-d) = x2
y2 + y*(a-b) - x*(c-d) = y2
令 t1 = a-b, t2 = c-d
-> x1 + x*t1 + y*t2 = x2 (1)
-> y1 + y*t1 - x*t2 = y2 (2)
问题就变为求解二元一次方程组,判断方程组是否有整数解
先消元,(1)*x + (2)*y -> x*(x1-x2) + y*(y1-y2) + t1*(x*x+y*y) = 0
-> t1 = (x*(x1-x2) + y*(y1-y2)) / (x*x+y*y) //要先判x,y是否均为0
若 y!=0 ,将 t1 带入式(1) ,得 t2 = -((x1-x2)+x*t1) / y
否则带入式(2),得 t2 = ((y1-y2)+y*t1) / x
将t1,t2带入下式判断是否成立
x1 + x*t1 + y*t2 = x2
y2 + y*t1 - x*t2 = y2
若成立则方程组有整数解
*/
#include <stdio.h>
#define LL long long
LL x1,y1,x2,y2,x,y; //分别代表向量A,B,C的坐标
LL X[5],Y[5]; //代表四个方向的B
int d[5][2][2] = {{{1,0},{0,1}},{{-1,0},{0,-1}},{{0,1},{-1,0}},{{0,-1},{1,0}}};
//便于得到四个方向
bool f(LL x2,LL y2){//判断A能否变为(x2, y2)
LL dx = x1-x2, dy = y1-y2;
LL sum = x * dx + y * dy;
LL t1 = -sum / (x*x+y*y);
if(y!=0){
LL t2 = -(dx+x*t1) / y;
if(x1+x*t1+y*t2==x2 && y1+y*t1-x*t2==y2) return 1;
}else{
LL t2 = (dy+y*t1) / x;
if(x1+x*t1+y*t2==x2 && y1+y*t1-x*t2==y2) return 1;
}
return 0;
}
int main()
{
scanf("%lld%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&x,&y);
for(int i=0;i<4;i++){
X[i] = d[i][0][0]*x2 + d[i][0][1]*y2;
Y[i] = d[i][1][0]*x2 + d[i][1][1]*y2;
}
int flag = 0;//判断能否从A变为B
if(x==0&&y==0){
//此时A不会变,只需判断A旋转后是否与B相同即可
for(int i=0;i<4;i++){
if(x1==X[i]&&y1==Y[i]) flag = 1;
}
}else{
for(int i=0;i<4;i++){
//判断A能否变为四个B中的其中一个
if(f(X[i], Y[i])) flag = 1;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
return 0;
}