> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Reaching Points Python Solution with Tests

> Tested Python solution for LeetCode 780 with 22 pytest cases. Generate a practice environment with lcpy.

LeetCode 780, [Hard](/catalog/hard). Topics: [Math](/catalog/topics/math), Euclidean Algorithm, Greatest Common Divisor. [View on LeetCode](https://leetcode.com/problems/reaching-points/description/).

Generate this problem as a practice environment: tested reference solution, 22 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 780   # by problem number
lcpy gen -s reaching_points   # by problem name
```

## Problem

Given four integers `sx`, `sy`, `tx`, and `ty`, return `true` if it is possible to convert the point `(sx, sy)` to the point `(tx, ty)` through some operations, or `false` otherwise.

The allowed operation on some point `(x, y)` is to convert it to either `(x, x + y)` or `(x + y, y)`.

### Examples

```
Input: sx = 1, sy = 1, tx = 3, ty = 5
Output: true
Explanation:
One series of moves that transforms the starting point to the target is:
(1, 1) -> (1, 2)
(1, 2) -> (3, 2)
(3, 2) -> (3, 5)
```

```
Input: sx = 1, sy = 1, tx = 2, ty = 2
Output: false
```

```
Input: sx = 1, sy = 1, tx = 1, ty = 1
Output: true
```

### Constraints

* 1 \<= sx, sy, tx, ty \<= 10^9

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reaching_points/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reaching_points/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(log(max(tx, ty)))
    # Space: O(1)
    def reaching_points(self, sx: int, sy: int, tx: int, ty: int) -> bool:
        # Walk backwards from the target: the parent of (x, y) is unique, so
        # collapse runs of same-axis moves with a modulo instead of subtracting.
        while tx > sx and ty > sy:
            if tx > ty:
                tx %= ty
            else:
                ty %= tx
        if tx == sx and ty == sy:
            return True
        if tx == sx and ty > sy:
            return (ty - sy) % tx == 0
        if ty == sy and tx > sx:
            return (tx - sx) % ty == 0
        return False
```

## Complexity

| Time | Space |
| - | - |
| O(log(max(tx, ty))) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.