Description
A ray starts from southwest corner of a square room with mirrors. Given p (room side) and q (receptor location), find which receptor is hit.
Examples
Input:
p = 2, q = 1Output:
2Explanation:
Laser hits receptor 2.
Input:
p = 4, q = 3Output:
0Explanation:
The laser bounces multiple times between the mirrors. After reflecting off the walls, it eventually reaches receptor 0 on the left wall.
Input:
p = 1, q = 2Output:
1Explanation:
With equal vertical distance but shorter horizontal distance, the laser reaches receptor 1 on the right wall after bouncing vertically.
Constraints
- •
1 ≤ p ≤ 1000