Leetcode Problem 858. Mirror Reflection

858. Mirror Reflection

Leetcode Solutions

Mathematical Approach using GCD

  1. Calculate the greatest common divisor (GCD) of p and q using Euclid's algorithm.
  2. Calculate the least common multiple (LCM) of p and q by multiplying p and q and then dividing by the GCD.
  3. Determine the number of reflections on the east wall by dividing the LCM by q.
  4. Determine the number of reflections on the north wall by dividing the LCM by p.
  5. If the number of reflections on the east wall is even, the ray hits receptor 0.
  6. If the number of reflections on the east wall is odd and the number of reflections on the north wall is odd, the ray hits receptor 1.
  7. If the number of reflections on the east wall is odd and the number of reflections on the north wall is even, the ray hits receptor 2.
UML Thumbnail

Simulation Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...