main idea:
- for nth tx,ty, ( assuming tx > ty), the nth tx comes from the (n-1)th tx + the (n-1)th ty ==> in order to make ty, tx increase, there has to be a difference between these two number
- for any sx > tx or sy > ty, there is no chance will change
- there is a case when tx == ts, which means all the time only ty is changed ==> ty = sy + k* sx, in this case, just to check if (ty-sy) % sx == 0
class Solution: # time O(lg(max(ty,tx))) space O(1) def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool: # big assumption: ty >= sy and tx >= sx while sx <= tx and sy <= ty: # case 1 ty == tx if tx == ty: break # case2 ty > tx # case 2.1 ty > sy # case 2.2 ty <= sy elif ty > tx: if tx == sx: return (ty-sy)%sx == 0 ty = ty % tx # case3 ty <= tx # case 3.1 tx > sx # case 3.2 tx <= sy elif ty < tx: if ty == sy: return (tx-sx)%sy == 0 tx = tx%ty return sx == tx and sy == ty