Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by n n n sectors, and the outer area is equally divided by m m m sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. A wall always exists at the 12 o’clock position.
The inner area’s sectors are denoted as ( 1 , 1 ) , ( 1 , 2 ) , … , ( 1 , n ) (1,1),(1,2),…,(1,n) (1,1),(1,2),…,(1,n) in clockwise direction. The outer area’s sectors are denoted as ( 2 , 1 ) , ( 2 , 2 ) , … , ( 2 , m ) (2,1),(2,2),…,(2,m) (2,1),(2,2),…,(2,m) in the same manner. For a clear understanding, see the example image above.
Amugae wants to know if he can move from one sector to another sector. He has q q q questions.
For each question, check if he can move between two given sectors.
The first line contains three integers $ n , m , q (1 \leq n,m \leq 10^{18}, 1 \leq q \leq 10^4) $— the number of sectors in the inner area, the number of sectors in the outer area and the number of questions.
Each of the next q q q lines contains four integers s x , s y , e x , e y ( 1 ≤ s x , e x ≤ 2 s_x, s_y, e_x, e_y (1 \leq s_x,e_x \leq 2 sx,sy,ex,ey(1≤sx,ex≤2; if$ s_x=1 , t h e n , then ,then 1 \leq s_y \leq n$, otherwise 1 ≤ s y ≤ m 1 \leq s_y \leq m 1≤sy≤m; constraints on e y e_y ey are similar). Amague wants to know if it is possible to move from sector$ (s_x,s_y) t o s e c t o r to sector tosector (e_x,e_y)$.
For each question, print “YES” if Amugae can move from ( s x , s y ) (sx,sy) (sx,sy) to ( e x , e y ) (ex,ey) (ex,ey), and “NO” otherwise.
You can print each letter in any case (upper or lower).
input
4 6 3
1 1 2 3
2 6 1 2
2 6 2 4
output
YES
NO
YES
Example is shown on the picture in the statement.
看到图就想到内圈每隔 x x x个,外圈每隔 y y y个,形成一个自闭组,那么这有什么关系吗?
有,每隔几个每隔几个,就是gcd的意义啊
那么思路清晰了,计算他们的gcd,就是最大公约数——代表着他们同时分成多少大自闭组,再分别用内外圈总数/自闭组数,就是内外圈每个自闭组包含几个单位范围,再确定询问的位置是否属于同一个自闭组,判断即可
/*********************
*@Author: ChenShou *
*@Language: C++11 *
*********************/
//#include
#pragma comment(linker, "/STACK:102400000,102400000")
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3f3f3f3f;
inline ll read(){
ll x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//cout.tie(0);
ll n=read(),m=read(),q=read();
ll ggcd=__gcd(n,m);
while(q--){
ll x_1=read(),y_1=read(),x_2=read(),y_2=read();
if(x_1!=x_2){
if(x_1==2&&x_2==1)swap(y_1,y_2);
ll num_1=n/ggcd,num_2=m/ggcd;
ll no_1=y_1/num_1,no_2=y_2/num_2;
if(y_1%num_1)no_1++;
if(y_2%num_2)no_2++;
if(no_1==no_2){
printf("YES\n");
}
else printf("NO\n");
}
else if(x_1==1){
ll num_1=n/ggcd,num_2=n/ggcd;
ll no_1=y_1/num_1,no_2=y_2/num_1;
if(y_1%num_1)no_1++;
if(y_2%num_1)no_2++;
if(no_1==no_2){
printf("YES\n");
}
else printf("NO\n");
}
else {
ll num_1=m/ggcd,num_2=m/ggcd;
ll no_1=y_1/num_1,no_2=y_2/num_2;
if(y_1%num_1)no_1++;
if(y_2%num_2)no_2++;
if(no_1==no_2){
printf("YES\n");
}
else printf("NO\n");
}
}
//continue;
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Fuck You !" << endl;
return 0;
}