Connection Status:
Competition Arena > PrettyPrintingProduct
SRM 420 · 2008-10-01 · by misof · Math
Class Name: PrettyPrintingProduct
Return Type: String
Method Name: prettyPrint
Arg Types: (int, int)
Problem Statement

Problem Statement

You will be given two 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 C = 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" (quotes for clarity only). Substitute the actual values of D and E into the output. If D has more than 10 digits, only output the first five and the last five digits of D, and separate them by three periods.

Notes

  • The purpose of the last constraint is to disallow inputs where precision problems could arise.

Constraints

  • A will be between 1 and 1,000,000, inclusive.
  • B will be between A and 1,000,000, inclusive.
  • If C has more than 10 digits, then the sixth most significant digit of C will be neither 0 nor 9.
Examples
0)
1
10
Returns: "36288 * 10^2"

1 * 2 * ... * 10 = 3628800 = 36288 * 10^2

1)
7
7
Returns: "7 * 10^0"

The product of all numbers between 7 and 7, inclusive, is obviously 7.

2)
211
214
Returns: "2038974024 * 10^0"

For this input D has 10 digits.

3)
411
414
Returns: "28952...24024 * 10^0"

For this input D has 11 digits. Note that we output three dots even if just one digit is missing in the output.

4)
412
415
Returns: "2923450236 * 10^1"

The actual value of C is larger than in the previous example. However, C ends in a zero and therefore D only has 10 digits.

11)
1
19
Returns: "12164...08832 * 10^3"

Note that the last five digits of D can start with a zero.

Submissions are judged against all 64 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PrettyPrintingProduct with a public method string prettyPrint(int A, int B) · 64 test cases · 2 s / 256 MB per case

Submitting as anonymous