#1006
Clumsy Factorial
specialist · 755 · lc medium +31 · verified · 61.1% accepted · 440 likes · top 61%
Description
The ordinary factorial of n multiplies all integers from 1 to n. The clumsy factorial replaces multiplications with a fixed cycle of operators *, /, +, - applied in decreasing order from n, respecting standard operator precedence and using floor division.
- For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.
Given an integer n, return its clumsy factorial.
Example 1:
Input: n = 4
Output: 7
Explanation: 7 = 4 * 3 / 2 + 1
Example 2:
Input: n = 10
Output: 12
Explanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1
Code
1
2
3