Problem Statement
S = { a1 * a2 * a3 : ai in Ri }
In other words, S is the set of all possible products formed by taking exactly one element from each of the three ranges. Return the number of distinct values in S.Definition
- Class:
- ProductSet
- Method:
- howMany
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int howMany(int[] lows, int[] highs)
- (be sure your method is public)
Constraints
- lows and highs will each contain exactly 3 elements.
- Each element of highs will be between 0 and 100, inclusive.
- Element i of lows will be between 0 and highs[i], inclusive.
Examples
{1,1,1}
{2,2,2}
Returns: 4
The possible distinct products are 1, 2, 4, and 8. All of the products are listed below: 1*1*1 = 1 1*1*2 = 2 1*2*1 = 2 1*2*2 = 4 2*1*1 = 2 2*1*2 = 4 2*2*1 = 4 2*2*2 = 8
{0,1,1}
{2,2,2}
Returns: 5
Now the possible products are 0, 1, 2, 4, and 8.
{0,0,0}
{100,100,100}
Returns: 46912
Note that the maximum possible product is 100*100*100 = 1 million. Marking off all possible products, we see there are only 46912 distinct values.
{100,100,1}
{100,100,1}
Returns: 1
{0,0,0}
{100,100,0}
Returns: 1
{1,1,0}
{1,1,92}
Returns: 93
{6,3,91}
{55,29,93}
Returns: 1824
{27,100,20}
{34,100,35}
Returns: 98
{53,4,4}
{87,53,89}
Returns: 26911
{8,0,15}
{17,5,82}
Returns: 1362
{39,0,44}
{79,41,52}
Returns: 7984
{19,98,78}
{57,99,93}
Returns: 1104
{6,66,12}
{6,67,12}
Returns: 2
{76,19,40}
{79,36,69}
Returns: 1523
{6,89,51}
{19,90,99}
Returns: 1002
{72,25,85}
{97,67,99}
Returns: 9258
{42,3,60}
{54,29,95}
Returns: 7276
{90,11,98}
{100,45,99}
Returns: 691
{9,95,32}
{89,95,56}
Returns: 1285
{48,36,99}
{67,99,99}
Returns: 946
{17,34,14}
{35,63,18}
Returns: 1524
{93,58,100}
{100,61,100}
Returns: 32
{76,46,92}
{90,75,93}
Returns: 837
{83,3,53}
{99,96,54}
Returns: 2741
{2,2,25}
{78,74,29}
Returns: 7700
{36,89,93}
{73,95,100}
Returns: 1847
{4,41,32}
{71,99,42}
Returns: 16362
{36,46,49}
{56,58,87}
Returns: 5359
{66,27,46}
{67,31,94}
Returns: 439
{91,29,87}
{98,60,97}
Returns: 1909
{56,56,40}
{67,61,61}
Returns: 1026
{91,56,13}
{99,60,87}
Returns: 3067
{38,97,37}
{39,98,61}
Returns: 98
{92,78,74}
{95,80,99}
Returns: 282
{50,92,67}
{63,95,97}
Returns: 1485
{70,70,25}
{89,84,87}
Returns: 8117
{81,73,74}
{100,98,77}
Returns: 1320
{99,7,59}
{100,59,70}
Returns: 1154
{45,91,97}
{51,94,98}
Returns: 54
{16,41,96}
{100,76,100}
Returns: 8414
{12,2,93}
{82,56,100}
Returns: 11898
{20,24,68}
{75,84,98}
Returns: 26648
{22,65,83}
{51,87,99}
Returns: 7399
{52,92,32}
{100,99,84}
Returns: 10737
{53,42,30}
{76,78,52}
Returns: 7813
{21,21,40}
{70,77,62}
Returns: 13828