Statistics

Problem Statement for "PrettyPrintingProduct"

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.

Definition

Class:
PrettyPrintingProduct
Method:
prettyPrint
Parameters:
int, int
Returns:
String
Method signature:
String prettyPrint(int A, int B)
(be sure your method is public)

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

  1. 1

    10

    Returns: "36288 * 10^2"

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

  2. 7

    7

    Returns: "7 * 10^0"

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

  3. 211

    214

    Returns: "2038974024 * 10^0"

    For this input D has 10 digits.

  4. 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.

  5. 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.

  6. 47

    4700

    Returns: "14806...28928 * 10^1163"

  7. 311

    314

    Returns: "9536499024 * 10^0"

  8. 312

    315

    Returns: "965915496 * 10^1"

  9. 1

    100000

    Returns: "28242...62496 * 10^24999"

  10. 1

    1000000

    Returns: "82639...12544 * 10^249998"

  11. 1000000

    1000000

    Returns: "1 * 10^6"

  12. 1

    19

    Returns: "12164...08832 * 10^3"

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

  13. 8

    25

    Returns: "30776...34496 * 10^5"

  14. 13

    25

    Returns: "32382...26624 * 10^4"

  15. 427784

    744439

    Returns: "11778...95584 * 10^79163"

  16. 448441

    732252

    Returns: "17954...99328 * 10^70953"

  17. 485137

    592122

    Returns: "15864...30656 * 10^26743"

  18. 453285

    495368

    Returns: "11029...67648 * 10^10519"

  19. 826677

    991147

    Returns: "22456...83328 * 10^41117"

  20. 82608

    853848

    Returns: "16549...75872 * 10^192808"

  21. 398036

    825775

    Returns: "74617...85408 * 10^106935"

  22. 551677

    622039

    Returns: "92473...10944 * 10^17589"

  23. 440532

    777613

    Returns: "90688...26912 * 10^84268"

  24. 124812

    480191

    Returns: "15181...62336 * 10^88846"

  25. 65043

    286828

    Returns: "63366...36224 * 10^55445"

  26. 803711

    967485

    Returns: "11565...14528 * 10^40942"

  27. 465688

    774960

    Returns: "48468...87488 * 10^77316"

  28. 44952

    779461

    Returns: "43655...84352 * 10^183626"

  29. 76

    89

    Returns: "66539...96032 * 10^2"

  30. 42

    99

    Returns: "27898...16032 * 10^13"

  31. 78

    83

    Returns: "27176...94656 * 10^1"

  32. 43

    97

    Returns: "68464...65248 * 10^13"

  33. 2

    16

    Returns: "20922...89888 * 10^3"

  34. 99

    99

    Returns: "99 * 10^0"

  35. 69

    70

    Returns: "483 * 10^1"

  36. 24

    87

    Returns: "81531...66816 * 10^16"

  37. 54

    81

    Returns: "13560...60384 * 10^7"

  38. 75

    88

    Returns: "56072...40416 * 10^4"

  39. 74

    81

    Returns: "12968...03136 * 10^3"

  40. 94

    97

    Returns: "8315616 * 10^1"

  41. 27

    88

    Returns: "45992...60768 * 10^14"

  42. 72

    99

    Returns: "10973...98688 * 10^6"

  43. 23

    69

    Returns: "15224...43968 * 10^11"

  44. 62

    92

    Returns: "24505...32544 * 10^7"

  45. 77

    78

    Returns: "6006 * 10^0"

  46. 1

    97

    Returns: "96192...83232 * 10^22"

  47. 82

    97

    Returns: "16593...05984 * 10^3"

  48. 936

    917877

    Returns: "47132...03616 * 10^229233"

  49. 4896

    915147

    Returns: "71131...58528 * 10^227561"

  50. 7392

    916397

    Returns: "56253...80128 * 10^227250"

  51. 5805

    945637

    Returns: "19689...37984 * 10^234958"

  52. 6925

    984811

    Returns: "23442...49344 * 10^244471"

  53. 8542

    935433

    Returns: "17118...46304 * 10^231721"

  54. 5028

    999058

    Returns: "37894...01792 * 10^248504"

  55. 1442

    974923

    Returns: "67157...09184 * 10^243367"

  56. 2359

    916372

    Returns: "18587...28544 * 10^228502"

  57. 9714

    909676

    Returns: "12844...57056 * 10^224991"

  58. 2

    1000000

    Returns: "82639...12544 * 10^249998"

  59. 2

    999999

    Returns: "82639...12544 * 10^249992"

  60. 1

    999999

    Returns: "82639...12544 * 10^249992"

  61. 4

    1000000

    Returns: "13773...35424 * 10^249998"

  62. 1

    999935

    Returns: "82811...39936 * 10^249978"

  63. 2851

    999998

    Returns: "16675...45312 * 10^249282"

  64. 3

    999999

    Returns: "41319...06272 * 10^249992"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: