(K, N)-Knight
Time limit1sMemory limit128 MB
Given K, N and two squares, decide whether a generalized knight that jumps K and N squares in either order can travel between them.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Graph, Implementation
- Solved
- No attempts yet
Problem
On an infinitely large chessboard you are given two squares and . Write a program that decides whether a -knight can travel from to .
A -knight moves much like an ordinary knight. In a single move it can jump to a square that is columns and rows away, or columns and rows away. In other words, from it moves to one of or . The ordinary chess knight is a -knight (equivalently a -knight).
Input
The first line contains the number of test cases (). Each test case is a single line with six integers , , , , , separated by spaces. (, , )
Output
For each test case, print TAK if the -knight can move from to , or NIE otherwise. Print one answer per line.