詳見這篇很是好的分析
AC代碼:c++
#include <bits/stdc++.h> using namespace std; #define LL long long LL gcd(LL a, LL b){ return b ? gcd(b, a%b):a; } int main(){ bool ans = true; LL p, q; LL x1, y1, x2, y2; LL dx, dy; cin >>p >>q; cin >>x1 >>y1 >>x2 >>y2; dx = x2-x1, dy = y2-y1; LL gd = gcd(p, q); if(dx % gd!=0 || dx%gd !=0){ ans = false; } else{ dx /= gd, dy /= gd; p /= gd, q /= gd; if(abs(dx%2) == abs(dy%2) || (abs(dx%2) != abs(dy%2) && abs(p%2) != abs(q%2)) ) ans = true; else ans = false; } if(ans ) cout <<"YES\n"; else cout <<"NO\n"; return 0; }