2543. Check if Point Is Reachable Hard

@problem@discussion
#Math#Number Theory



1/**
2 * [2543] Check if Point Is Reachable
3 *
4 * There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.
5 * In one step, you can move from point (x, y) to any one of the following points:
6 * 
7 * 	(x, y - x)
8 * 	(x - y, y)
9 * 	(2 * x, y)
10 * 	(x, 2 * y)
11 * 
12 * Given two integers targetX and targetY representing the X-coordinate and Y-coordinate of your final position, return true if you can reach the point from (1, 1) using some number of steps, and false otherwise.
13 *  
14 * <strong class="example">Example 1:
15 * 
16 * Input: targetX = 6, targetY = 9
17 * Output: false
18 * Explanation: It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.
19 * 
20 * <strong class="example">Example 2:
21 * 
22 * Input: targetX = 4, targetY = 7
23 * Output: true
24 * Explanation: You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7).
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= targetX, targetY <= 10^9
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/check-if-point-is-reachable/
35// discuss: https://leetcode.com/problems/check-if-point-is-reachable/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn is_reachable(target_x: i32, target_y: i32) -> bool {
41        false
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2543() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.