1553. Minimum Number of Days to Eat N Oranges Hard
1/**
2 * [1553] Minimum Number of Days to Eat N Oranges
3 *
4 * There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:
5 *
6 * Eat one orange.
7 * If the number of remaining oranges n is divisible by 2 then you can eat n / 2 oranges.
8 * If the number of remaining oranges n is divisible by 3 then you can eat 2 * (n / 3) oranges.
9 *
10 * You can only choose one of the actions per day.
11 * Given the integer n, return the minimum number of days to eat n oranges.
12 *
13 * Example 1:
14 *
15 * Input: n = 10
16 * Output: 4
17 * Explanation: You have 10 oranges.
18 * Day 1: Eat 1 orange, 10 - 1 = 9.
19 * Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)
20 * Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1.
21 * Day 4: Eat the last orange 1 - 1 = 0.
22 * You need at least 4 days to eat the 10 oranges.
23 *
24 * Example 2:
25 *
26 * Input: n = 6
27 * Output: 3
28 * Explanation: You have 6 oranges.
29 * Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).
30 * Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)
31 * Day 3: Eat the last orange 1 - 1 = 0.
32 * You need at least 3 days to eat the 6 oranges.
33 *
34 *
35 * Constraints:
36 *
37 * 1 <= n <= 2 * 10^9
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges/
43// discuss: https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn min_days(n: i32) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_1553() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.