Abbreviating the Product of a Range - Problem
You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].
Since the product may be very large, you will abbreviate it following these steps:
- Count all trailing zeros in the product and remove them. Let us denote this count as
C. - Denote the remaining number of digits in the product as
d. Ifd > 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. Ifd <= 10, we keep it unchanged. - Finally, represent the product as a string
"<pre>...<suf>eC".
Return a string denoting the abbreviated product of all integers in the inclusive range [left, right].
Input & Output
Example 1 — Small Range
$
Input:
left = 1, right = 4
›
Output:
24e0
💡 Note:
Product is 1×2×3×4 = 24. No trailing zeros. Since 24 has 2 digits (≤ 10), return "24e0".
Example 2 — With Trailing Zeros
$
Input:
left = 2, right = 5
›
Output:
12e1
💡 Note:
Product is 2×3×4×5 = 120. Remove 1 trailing zero → 12. Since 12 has 2 digits (≤ 10), return "12e1".
Example 3 — Large Range
$
Input:
left = 1, right = 18
›
Output:
64023...05728e3
💡 Note:
Product is 18! = 6402373705728000. Remove 3 trailing zeros → 6402373705728. Since this has 13 digits (>10), return first 5 digits + '...' + last 5 digits + 'e3'.
Constraints
- 1 ≤ left ≤ right ≤ 104
- The product can be extremely large
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code