2998. Minimum Number of Operations to Make X and Y Equal Medium
1/**
2 * [2998] Minimum Number of Operations to Make X and Y Equal
3 *
4 * You are given two positive integers x and y.
5 * In one operation, you can do one of the four following operations:
6 * <ol>
7 * Divide x by 11 if x is a multiple of 11.
8 * Divide x by 5 if x is a multiple of 5.
9 * Decrement x by 1.
10 * Increment x by 1.
11 * </ol>
12 * Return the minimum number of operations required to make x and y equal.
13 *
14 * <strong class="example">Example 1:
15 *
16 * Input: x = 26, y = 1
17 * Output: 3
18 * Explanation: We can make 26 equal to 1 by applying the following operations:
19 * 1. Decrement x by 1
20 * 2. Divide x by 5
21 * 3. Divide x by 5
22 * It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.
23 *
24 * <strong class="example">Example 2:
25 *
26 * Input: x = 54, y = 2
27 * Output: 4
28 * Explanation: We can make 54 equal to 2 by applying the following operations:
29 * 1. Increment x by 1
30 * 2. Divide x by 11
31 * 3. Divide x by 5
32 * 4. Increment x by 1
33 * It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.
34 *
35 * <strong class="example">Example 3:
36 *
37 * Input: x = 25, y = 30
38 * Output: 5
39 * Explanation: We can make 25 equal to 30 by applying the following operations:
40 * 1. Increment x by 1
41 * 2. Increment x by 1
42 * 3. Increment x by 1
43 * 4. Increment x by 1
44 * 5. Increment x by 1
45 * It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.
46 *
47 *
48 * Constraints:
49 *
50 * 1 <= x, y <= 10^4
51 *
52 */
53pub struct Solution {}
54
55// problem: https://leetcode.com/problems/minimum-number-of-operations-to-make-x-and-y-equal/
56// discuss: https://leetcode.com/problems/minimum-number-of-operations-to-make-x-and-y-equal/discuss/?currentPage=1&orderBy=most_votes&query=
57
58// submission codes start here
59
60impl Solution {
61 pub fn minimum_operations_to_make_equal(x: i32, y: i32) -> i32 {
62 0
63 }
64}
65
66// submission codes end
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn test_2998() {
74 }
75}
76
Back
© 2025 bowen.ge All Rights Reserved.