Statistics

Problem Statement for "ProductSet"

Problem Statement

You are given three inclusive ranges of nonnegative integers. Ri = [ lows[i], highs[i] ] denotes the ith range. Define the set S as follows:
	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,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

  2. {0,1,1}

    {2,2,2}

    Returns: 5

    Now the possible products are 0, 1, 2, 4, and 8.

  3. {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.

  4. {100,100,1}

    {100,100,1}

    Returns: 1

  5. {0,0,0}

    {100,100,0}

    Returns: 1

  6. {1,1,0}

    {1,1,92}

    Returns: 93

  7. {6,3,91}

    {55,29,93}

    Returns: 1824

  8. {27,100,20}

    {34,100,35}

    Returns: 98

  9. {53,4,4}

    {87,53,89}

    Returns: 26911

  10. {8,0,15}

    {17,5,82}

    Returns: 1362

  11. {39,0,44}

    {79,41,52}

    Returns: 7984

  12. {19,98,78}

    {57,99,93}

    Returns: 1104

  13. {6,66,12}

    {6,67,12}

    Returns: 2

  14. {76,19,40}

    {79,36,69}

    Returns: 1523

  15. {6,89,51}

    {19,90,99}

    Returns: 1002

  16. {72,25,85}

    {97,67,99}

    Returns: 9258

  17. {42,3,60}

    {54,29,95}

    Returns: 7276

  18. {90,11,98}

    {100,45,99}

    Returns: 691

  19. {9,95,32}

    {89,95,56}

    Returns: 1285

  20. {48,36,99}

    {67,99,99}

    Returns: 946

  21. {17,34,14}

    {35,63,18}

    Returns: 1524

  22. {93,58,100}

    {100,61,100}

    Returns: 32

  23. {76,46,92}

    {90,75,93}

    Returns: 837

  24. {83,3,53}

    {99,96,54}

    Returns: 2741

  25. {2,2,25}

    {78,74,29}

    Returns: 7700

  26. {36,89,93}

    {73,95,100}

    Returns: 1847

  27. {4,41,32}

    {71,99,42}

    Returns: 16362

  28. {36,46,49}

    {56,58,87}

    Returns: 5359

  29. {66,27,46}

    {67,31,94}

    Returns: 439

  30. {91,29,87}

    {98,60,97}

    Returns: 1909

  31. {56,56,40}

    {67,61,61}

    Returns: 1026

  32. {91,56,13}

    {99,60,87}

    Returns: 3067

  33. {38,97,37}

    {39,98,61}

    Returns: 98

  34. {92,78,74}

    {95,80,99}

    Returns: 282

  35. {50,92,67}

    {63,95,97}

    Returns: 1485

  36. {70,70,25}

    {89,84,87}

    Returns: 8117

  37. {81,73,74}

    {100,98,77}

    Returns: 1320

  38. {99,7,59}

    {100,59,70}

    Returns: 1154

  39. {45,91,97}

    {51,94,98}

    Returns: 54

  40. {16,41,96}

    {100,76,100}

    Returns: 8414

  41. {12,2,93}

    {82,56,100}

    Returns: 11898

  42. {20,24,68}

    {75,84,98}

    Returns: 26648

  43. {22,65,83}

    {51,87,99}

    Returns: 7399

  44. {52,92,32}

    {100,99,84}

    Returns: 10737

  45. {53,42,30}

    {76,78,52}

    Returns: 7813

  46. {21,21,40}

    {70,77,62}

    Returns: 13828


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: