# Problem Description
This is a laser path prediction problem in a square grid where:
- A laser emitter shoots a beam from the bottom-left corner
- The beam reflects off the walls following the law of reflection
- There are three receivers (A, B, C) at different corners
- We need to determine which receiver the laser will hit first based on given x and y coordinates
- The coordinates (x,y) define the initial trajectory angle of the laser beam

# Visual Facts
1. Physical Layout:
   - Square-shaped area with reflective boundaries (marked by diagonal lines)
   - Laser emitter at bottom-left corner
   - Receiver A at bottom-right corner
   - Receiver B at top-right corner
   - Receiver C at top-left corner
   
2. Path Visualization:
   - Green arrows show the laser path
   - Orange line marked 'x' along bottom
   - Blue line marked 'y' along right side
   - Laser follows a zigzag pattern
   - Path reflects off boundaries maintaining equal angles

# Visual Patterns
1. Mathematical Properties:
   - The ratio y/x determines the initial angle of the laser
   - The laser path forms a repeating pattern based on x and y values
   - GCD reduction pattern: (x,y) can be reduced to lowest terms

2. Path Determination Rules:
   - When x is even and y is odd: Laser reaches receiver C
   - When x is odd and y is even: Laser reaches receiver A
   - When both x and y are odd: Laser reaches receiver B
   - When both x and y are even: Laser reaches receiver C (after GCD reduction)

3. Geometric Patterns:
   - Each reflection maintains the same angle with the boundary
   - The path forms a regular pattern that depends on the parity of x and y
   - The final destination is determined by how many reflections occur before hitting a corner
   - The GCD reduction doesn't change the final destination but simplifies the calculation


# Solution
from math import gcd

def solution(x: int, y: int) -> str:
    """
    Determine the first laser receiver encountered by the laser in the square area

    Parameters:
        x (int): The length of x.
        y (int): The length of y.

    Returns:
        str: The identifier of the first laser receiver encountered by the laser. ('A', 'B', or, 'C')
    """
    g = gcd(x, y)
    x = (x / g) % 2
    y = (y / g) % 2
    return 'B' if x and y else 'A' if x else 'C'


# Test Script
def test():
    test_cases = [
        (2, 1, 'C'),
        (3, 1, 'B'),
        (3, 2, 'A'),
        (3, 3, 'B'),
        (4, 1, 'C'),
        (4, 2, 'C'),
        (4, 3, 'C'),
        (4, 4, 'B'),
        (5, 1, 'B'),
        (5, 2, 'A'),
    ]

    for i, (x, y, expected_output) in enumerate(test_cases):
        try:
            output = solution(x, y)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`x`: {x}\n"
                f"`y`: {y}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`x`: {x}\n"
                f"`y`: {y}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()