Help Needed in a question

Question :
You will be given 2 positive ints A and B.
Let C be the product of all integers between A and B, inclusive.
The number C has a unique representation of the form D * 10^E, where D and E are non-negative integers and the last digit of D is non-zero.
Write a method that will return the value of C formatted as a string of the form “D * 10^E”. Substitute the actual values of D and E into the output. If D has more than 10 digits, only output the first five and last five digits of D, and separate them by three periods.


  • 1 <= A <= 1000000
  • A <= B <= 1000000
  • If C has more than 10 digits, then the sixth most significant digit of C will be neither 0 nor 9

Sample Test Cases :

  • Input 1
    1 10

  • Output 1
    36288 * 10^2

  • Input 2
    211 214

  • Output 2
    2038974024 * 10^0

  • Input 3
    411 414

  • Output 3
    28952…24024 * 10^0

My idea of the solution

Since the product can be really large we will represent it as the product of the powers of its prime factors which can be done using Sieve technique. Then the value of E will be simply the min(cnt[2],cnt[5]) as 10^x = 2^x * 5^x.
Now what remains is finding the first five and last five digits of the remaining product.
Last five digits can be found by taking %100000 while multiplying them.
But I am not able to figure out how to find the first five digits of the products.

Any kind of help would be appreciated.
Thanks in advance…!
@vijju532 @ssjgz

please give me the solutions of these problem