Problem statement

https://binarysearch.com/problems/Traverse-Coordinates/

Solution

Equal to Leetcode 0780 Reaching Points.

Complexity

Time complexity is O(log(sx) + log(sy)). Space as well.

Code

class Solution:
    def solve(self, sx, sy, tx, ty):
        while tx > 0 and ty > 0:
            if tx >= ty:
                if sy == ty and (tx-sx)%ty == 0 and tx >= sx: return True
            else:
                if sx == tx and (ty-sy)%tx == 0 and ty >= sy: return True
           
            tx, ty = tx%ty, ty%tx
        return False