Best Performing Solution | Simple Python | Math | Very Detailed Explanation | Scientific Notation ✨
UPVOTE is Highly Appreciated\n\n# Intuition\nUsing float or double to record prefix, inspired by scientific notation\n\n# Approach\n1. keep 0.1 <= prod < 1.0, s
**UPVOTE is Highly Appreciated**\n\n# Intuition\nUsing float or double to record prefix, inspired by scientific notation\n\n# Approach\n1. keep `0.1 <= prod < 1.0`, so len(str`(int(product * 100000))) == 5`, just like scientific notation\n\n2. so we can easily get `prefix` via `prefix = str(int(product * 100000))`\n\n3. `org_digits` is the number of digits of the original very very large product number, `zeros` is the number of its trailing zeros, so that `org_digits - zeros` is the number of its actual non-zero digits.\n\n4. The error of `suffix` can only come from the trailing zeros.\n\n5. Although we remove all of the trailing zeros every time and then take the modulus, but 2 and 5 as the division of `suffix` may squeeze the effective digit length.\n\n6. so if we want to keep the exactly accurate last 5 Digits, we need to increase the digit length.\n\n7. Since `n` is less than or equal to `10 ** 4`, there are no more than 5 trailing zeros that can be eliminated at one time. So to not waste memory we asiign `suffix %= 10 ** 14` is large enough to keep accurate 5 digits of `suffix`.\n\n8. Another reason we chose `10 ** 14` is that `(10 ** 14) * (10 ** 4) = 10 ** 18` is in the range of int64, so it can be easily migrated to other programming languages as well.\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution(object):\n\tdef abbreviateProduct(self, left, right):\n\t\tproduct, suffix, zeros, org_digits = 1.0, 1, 0, 0\n\t\tfor n in range(left, right + 1):\n\t\t\tproduct *= n\n\t\t\twhile product >= 1:  # keep 0.1 <= prod < 1.0, so len(str(int(prod * 100000))) == 5\n\t\t\t\tproduct /= 10\n\t\t\t\torg_digits += 1  # add 1 while remove 1 digit\n\t\t\tsuffix *= n\n\t\t\twhile suffix % 10 == 0:  # count and remove the trailing zeros\n\t\t\t\tzeros += 1\n\t\t\t\tsuffix //= 10\n\t\t\tif suffix > 10 ** 14:\n\t\t\t\tsuffix %= 10 ** 14\n\t\tif org_digits - zeros <= 10:\n\t\t\treturn str(int(product * (10 ** (org_digits - zeros)) + 0.5)) + \'e\' + str(zeros)\n\t\telse:\n\t\t\treturn str(int(product * 100000)) + \'...\' + (\'0000\' + str(suffix))[-5:] + \'e\' + str(zeros)\n```
['Math', 'Brainteaser', 'Python', 'Python3']