#P1170. Safe Orchard? Determining Bugs Bunny's Safety
Safe Orchard? Determining Bugs Bunny's Safety
Safe Orchard? Determining Bugs Bunny's Safety
Bugs Bunny is hiding under a tree in an orchard adjacent to a forest. The orchard contains an grid of trees arranged in rows and columns, where the distance between two horizontally or vertically adjacent trees is . A hunter, armed with a shotgun, enters the orchard and climbs a tree to kill Bugs Bunny. The hunter can see Bugs Bunny if there is no other tree on the straight line connecting their respective trees. In other words, if the greatest common divisor (gcd) of the differences in their row and column indices is , there will be no intermediate tree blocking the line of sight, and the hunter will be able to see Bugs Bunny.
Given the positions of Bugs Bunny and the hunter (both corresponding to tree locations), determine whether Bugs Bunny is safe. Bugs Bunny is considered safe if there is at least one other tree on the line between them (i.e. when the gcd of the differences is greater than ).
inputFormat
The input consists of three lines:
- The first line contains two integers and , representing the number of rows and columns in the orchard.
- The second line contains two integers and , representing the row and column of Bugs Bunny's tree.
- The third line contains two integers and , representing the row and column of the hunter's tree. It is guaranteed that both positions lie within the grid.
outputFormat
Output a single word:
- Print
YES
if Bugs Bunny is safe (i.e. there exists at least one tree on the line between the hunter and Bugs Bunny), - Otherwise, print
NO
(if the hunter can see Bugs Bunny).
sample
5 5
1 1
1 2
NO
</p>