-
Notifications
You must be signed in to change notification settings - Fork 103
/
AE2B.cpp
52 lines (47 loc) · 1007 Bytes
/
AE2B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
USER: zobayer
TASK: AE2B
ALGO: math
*/
#include <stdio.h>
const int BUFF = 1280000;
static char buff[BUFF], *ptr;
inline int gcd(int a, int b) {
while(b) b ^= a ^= b ^= a %= b;
return a;
}
inline int nextInt() {
while(*ptr != '-' && (*ptr < '0' || *ptr > '9')) ptr++;
int minus = 0, ret = 0;
if(*ptr=='-') minus = 1, ptr++;
while(*ptr >= '0' && *ptr <= '9') ret = ret * 10 + *ptr - '0', ptr++;
if(minus) ret = -ret;
return ret;
}
int main() {
int test, k, n, dx, dy, x1, y1, x2, y2, g;
fread(buff, BUFF, 1, stdin); ptr = buff;
test = nextInt();
while(test--) {
k = nextInt();
n = nextInt();
x1 = nextInt();
y1 = nextInt();
x2 = nextInt();
y2 = nextInt();
g = gcd(k, n);
dx = x1 > x2? x1 - x2 : x2 - x1;
dy = y1 > y2? y1 - y2 : y2 - y1;
if(g > 1) {
if(dx % g || dy % g) {
puts("NIE");
continue;
}
k /= g, n /= g, dx /= g, dy /= g;
}
if(!(k&1) || !(n&1)) puts("TAK");
else if((dx&1) + (dy&1) == 1) puts("NIE");
else puts("TAK");
}
return 0;
}