Statistics

Problem Statement for "KLastNonZeroDigits"

Problem Statement

You are given an int N. The factorial of N is defined as N*(N-1)*(N-2)*...*1. Compute the factorial of N and remove all of its rightmost zero digits. If the result is more than K digits long, return the last K digits as a string. Otherwise, return the entire result as a string.

Definition

Class:
KLastNonZeroDigits
Method:
getKDigits
Parameters:
int, int
Returns:
String
Method signature:
String getKDigits(int N, int K)
(be sure your method is public)

Constraints

  • N will be between 1 and 20, inclusive.
  • K will be between 1 and 9, inclusive.

Examples

  1. 10

    3

    Returns: "288"

    You would first compute the factorial of 10, which is 10*9*8*7*6*5*4*3*2*1=3628800. You would then remove all rightmost zeros to get 36288. Finally, you would return the last 3 digits as a string: "288".

  2. 6

    1

    Returns: "2"

    The factorial of 6 is 720.

  3. 6

    3

    Returns: "72"

  4. 7

    2

    Returns: "04"

    The factorial of 7 is 5040. We remove the last zero to get "504". The last 2 digits of "504" are "04".

  5. 20

    9

    Returns: "200817664"

  6. 16

    6

    Returns: "789888"

  7. 16

    1

    Returns: "8"

  8. 17

    6

    Returns: "428096"

  9. 3

    8

    Returns: "6"

  10. 18

    8

    Returns: "73705728"

  11. 6

    8

    Returns: "72"

  12. 16

    9

    Returns: "922789888"

  13. 20

    4

    Returns: "7664"

  14. 6

    7

    Returns: "72"

  15. 6

    3

    Returns: "72"

  16. 13

    7

    Returns: "2270208"

  17. 11

    7

    Returns: "399168"

  18. 16

    3

    Returns: "888"

  19. 18

    7

    Returns: "3705728"

  20. 4

    5

    Returns: "24"

  21. 8

    7

    Returns: "4032"

  22. 1

    6

    Returns: "1"

  23. 5

    2

    Returns: "12"

  24. 19

    3

    Returns: "832"

  25. 10

    5

    Returns: "36288"

  26. 1

    1

    Returns: "1"

  27. 20

    1

    Returns: "4"

  28. 19

    8

    Returns: "00408832"

  29. 20

    8

    Returns: "00817664"

  30. 8

    3

    Returns: "032"

  31. 14

    9

    Returns: "871782912"

  32. 13

    9

    Returns: "62270208"

  33. 3

    8

    Returns: "6"

  34. 15

    1

    Returns: "8"

  35. 6

    3

    Returns: "72"

  36. 1

    9

    Returns: "1"

  37. 1

    5

    Returns: "1"

  38. 4

    8

    Returns: "24"

  39. 10

    6

    Returns: "36288"

  40. 20

    9

    Returns: "200817664"

  41. 10

    3

    Returns: "288"

  42. 7

    2

    Returns: "04"

  43. 8

    3

    Returns: "032"

  44. 5

    9

    Returns: "12"

  45. 15

    2

    Returns: "68"

  46. 2

    2

    Returns: "2"

  47. 2

    9

    Returns: "2"

  48. 18

    9

    Returns: "373705728"

  49. 17

    9

    Returns: "687428096"

  50. 20

    7

    Returns: "0817664"

  51. 19

    9

    Returns: "100408832"

  52. 20

    8

    Returns: "00817664"

  53. 3

    5

    Returns: "6"

  54. 5

    1

    Returns: "2"

  55. 19

    8

    Returns: "00408832"


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: