1006. Clumsy Factorial Medium
1/**
2 * [1006] Clumsy Factorial
3 *
4 * The factorial of a positive integer n is the product of all positive integers less than or equal to n.
5 *
6 * For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.
7 *
8 * We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply '*', divide '/', add '+', and subtract '-' in this order.
9 *
10 * For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.
11 *
12 * However, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.
13 * Additionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11.
14 * Given an integer n, return the clumsy factorial of n.
15 *
16 * Example 1:
17 *
18 * Input: n = 4
19 * Output: 7
20 * Explanation: 7 = 4 * 3 / 2 + 1
21 *
22 * Example 2:
23 *
24 * Input: n = 10
25 * Output: 12
26 * Explanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1
27 *
28 *
29 * Constraints:
30 *
31 * 1 <= n <= 10^4
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/clumsy-factorial/
37// discuss: https://leetcode.com/problems/clumsy-factorial/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn clumsy(n: i32) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_1006() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.