Problem Statement
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
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
"193"
{82,13,100}
Returns: 0
Our existing sizes already have a big enough lcm.
"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.)
"999999"
{124,600,7,8}
Returns: 11
"2000000000"
{20,77,13,17,19}
Returns: 40
"199456"
{7,7,7,7,7,7}
Returns: 46
"2000000000"
{3, 5, 7, 11, 13, 17, 19, 23, 29}
Returns: 0
"1000000000000000"
{1}
Returns: 243
"2000000000"
{1}
Returns: 112
"999999999999999"
{2, 3, 113}
Returns: 192
"456487258283017"
{161, 102, 911, 236, 209, 266, 625}
Returns: 8
"47446"
{46, 4, 45, 14}
Returns: 8
"27584"
{17, 43, 6}
Returns: 7
"103"
{24}
Returns: 5
"3"
{16}
Returns: 0
"754"
{29, 13}
Returns: 2
"1"
{5}
Returns: 0
"5040"
{36, 16}
Returns: 12
"987654321054321"
{2, 3, 4, 8, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}
Returns: 0
"123456789123"
{31,1,1,6}
Returns: 120
"123456789123456"
{8,37,125,49}
Returns: 115
"926850925000000"
{8,37,125,49,121,169}
Returns: 68
"926850925000001"
{8,37,125,49,121,169}
Returns: 68
"287323786750"
{37,125,49,121,169,31}
Returns: 2
"287323786751"
{37,125,49,121,169,31}
Returns: 3
"287323786751"
{37,125,49,121,169,31,997,997,997,997,991}
Returns: 0