2117. Abbreviating the Product of a Range Hard
1/**
2 * [2117] Abbreviating the Product of a Range
3 *
4 * You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].
5 * Since the product may be very large, you will abbreviate it following these steps:
6 * <ol>
7 * Count all trailing zeros in the product and remove them. Let us denote this count as C.
8 *
9 * For example, there are 3 trailing zeros in 1000, and there are 0 trailing zeros in 546.
10 *
11 *
12 * Denote the remaining number of digits in the product as d. If d > 10, then express the product as <pre>...<suf> where <pre> denotes the first 5 digits of the product, and <suf> denotes the last 5 digits of the product after removing all trailing zeros. If d <= 10, we keep it unchanged.
13 *
14 * For example, we express 1234567654321 as 12345...54321, but 1234567 is represented as 1234567.
15 *
16 *
17 * Finally, represent the product as a string "<pre>...<suf>eC".
18 *
19 * For example, 12345678987600000 will be represented as "12345...89876e5".
20 *
21 *
22 * </ol>
23 * Return a string denoting the abbreviated product of all integers in the inclusive range [left, right].
24 *
25 * Example 1:
26 *
27 * Input: left = 1, right = 4
28 * Output: "24e0"
29 * Explanation: The product is 1 × 2 × 3 × 4 = 24.
30 * There are no trailing zeros, so 24 remains the same. The abbreviation will end with "e0".
31 * Since the number of digits is 2, which is less than 10, we do not have to abbreviate it further.
32 * Thus, the final representation is "24e0".
33 *
34 * Example 2:
35 *
36 * Input: left = 2, right = 11
37 * Output: "399168e2"
38 * Explanation: The product is 39916800.
39 * There are 2 trailing zeros, which we remove to get 399168. The abbreviation will end with "e2".
40 * The number of digits after removing the trailing zeros is 6, so we do not abbreviate it further.
41 * Hence, the abbreviated product is "399168e2".
42 *
43 * Example 3:
44 *
45 * Input: left = 371, right = 375
46 * Output: "7219856259e3"
47 * Explanation: The product is 7219856259000.
48 *
49 *
50 * Constraints:
51 *
52 * 1 <= left <= right <= 10^4
53 *
54 */
55pub struct Solution {}
56
57// problem: https://leetcode.com/problems/abbreviating-the-product-of-a-range/
58// discuss: https://leetcode.com/problems/abbreviating-the-product-of-a-range/discuss/?currentPage=1&orderBy=most_votes&query=
59
60// submission codes start here
61
62impl Solution {
63 pub fn abbreviate_product(left: i32, right: i32) -> String {
64 String::new()
65 }
66}
67
68// submission codes end
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73
74 #[test]
75 fn test_2117() {
76 }
77}
78
Back
© 2025 bowen.ge All Rights Reserved.