1from collections import defaultdict234class Solution:5def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:6def nextNum(ta, tb, s):7if ta % tb == s % tb:8return min(ta, s)9return ta % tb1011visited = defaultdict(bool)12while tx >= sx and ty >= sy and (sx != tx or sy != ty):13if tx > ty:14tx, ty = nextNum(tx, ty, sx), ty15else:16tx, ty = tx, nextNum(ty, tx, sy)17if visited[(tx, ty)]:18break19visited[(tx, ty)] = True20return (sx == tx) and (sy == ty)