Statistics

Problem Statement for "ToolingUp"

Problem Statement

The least common multiple (lcm) of a set of positive integers is the smallest integer that is divisible by each member of the set. It is frequently desirable to have a collection of numbers whose lcm is large.

We want to manufacture parts in a greater variety of sizes -- specifically our goal is to offer sizes whose lcm is greater than or equal to targetLcm. But every new size s that we manufacture costs us s dollars to tool up to produce.

The int[] sizes contains all the sizes we are currently producing. The String targetLcm represents an integer with no leading zeroes. Return the minimum cost of offering additional sizes that will let us achieve our goal.

Definition

Class:
ToolingUp
Method:
cost
Parameters:
String, int[]
Returns:
int
Method signature:
int cost(String targetLcm, int[] sizes)
(be sure your method is public)

Constraints

  • targetLcm will contain only digits ('0' - '9').
  • targetLcm will represent an integer between 1 and 1015, inclusive.
  • targetLcm will not contain leading zeroes.
  • sizes will contain between 1 and 50 elements, inclusive.
  • Each element of sizes will be between 1 and 1000, inclusive.

Examples

  1. "193"

    {82,13,100}

    Returns: 0

    Our existing sizes already have a big enough lcm.

  2. "1000000"

    {100,92,77}

    Returns: 9

    We can produce a single new size of 9 to get an lcm greater than 1,000,000. (We could also achieve our goal by adding the two sizes 3 and 8, but that would cost 11.)

  3. "999999"

    {124,600,7,8}

    Returns: 11

  4. "2000000000"

    {20,77,13,17,19}

    Returns: 40

  5. "199456"

    {7,7,7,7,7,7}

    Returns: 46

  6. "2000000000"

    {3, 5, 7, 11, 13, 17, 19, 23, 29}

    Returns: 0

  7. "1000000000000000"

    {1}

    Returns: 243

  8. "2000000000"

    {1}

    Returns: 112

  9. "999999999999999"

    {2, 3, 113}

    Returns: 192

  10. "456487258283017"

    {161, 102, 911, 236, 209, 266, 625}

    Returns: 8

  11. "47446"

    {46, 4, 45, 14}

    Returns: 8

  12. "27584"

    {17, 43, 6}

    Returns: 7

  13. "103"

    {24}

    Returns: 5

  14. "3"

    {16}

    Returns: 0

  15. "754"

    {29, 13}

    Returns: 2

  16. "1"

    {5}

    Returns: 0

  17. "5040"

    {36, 16}

    Returns: 12

  18. "987654321054321"

    {2, 3, 4, 8, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}

    Returns: 0

  19. "123456789123"

    {31,1,1,6}

    Returns: 120

  20. "123456789123456"

    {8,37,125,49}

    Returns: 115

  21. "926850925000000"

    {8,37,125,49,121,169}

    Returns: 68

  22. "926850925000001"

    {8,37,125,49,121,169}

    Returns: 68

  23. "287323786750"

    {37,125,49,121,169,31}

    Returns: 2

  24. "287323786751"

    {37,125,49,121,169,31}

    Returns: 3

  25. "287323786751"

    {37,125,49,121,169,31,997,997,997,997,991}

    Returns: 0


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: