Statistics

Problem Statement for "FractionCounting"

Problem Statement

Consider the following set (see notes for clarification):
  S = {  p/q  |   w <= p <= x,  y <= q <= z  }
Given w, x, y, and z return the number of distinct elements in S.

Definition

Class:
FractionCounting
Method:
howMany
Parameters:
int, int, int, int
Returns:
int
Method signature:
int howMany(int w, int x, int y, int z)
(be sure your method is public)

Notes

  • S is the set of all rational numbers whose numerators are between w and x inclusive, and whose denominators are between y and z inclusive.

Constraints

  • x and z will be between 1 and 100, inclusive.
  • w will be between 1 and x, inclusive.
  • y will be between 1 and z, inclusive.

Examples

  1. 1

    1

    1

    1

    Returns: 1

    Only the value 1/1 is being considered.

  2. 1

    10

    1

    1

    Returns: 10

    Here S contains the values 1,...,10.

  3. 1

    1

    1

    10

    Returns: 10

  4. 1

    2

    1

    2

    Returns: 3

    Here the values are 1/1, 1/2, 2/1, and 2/2. Since 2/2 = 1/1 the answer is 3.

  5. 2

    4

    2

    4

    Returns: 7

  6. 1

    100

    1

    100

    Returns: 6087

  7. 67

    74

    81

    85

    Returns: 40

  8. 42

    58

    56

    61

    Returns: 99

  9. 5

    40

    7

    73

    Returns: 1575

  10. 85

    97

    25

    70

    Returns: 580

  11. 2

    23

    86

    99

    Returns: 299

  12. 15

    82

    91

    93

    Returns: 204

  13. 67

    99

    77

    83

    Returns: 225

  14. 20

    29

    11

    67

    Returns: 502

  15. 6

    84

    53

    95

    Returns: 2863

  16. 73

    97

    77

    88

    Returns: 287

  17. 83

    95

    66

    90

    Returns: 313

  18. 17

    95

    53

    69

    Returns: 1250

  19. 93

    96

    78

    79

    Returns: 8

  20. 46

    93

    30

    99

    Returns: 2794

  21. 24

    82

    85

    90

    Returns: 347

  22. 63

    82

    46

    77

    Returns: 594

  23. 73

    95

    57

    78

    Returns: 479

  24. 93

    96

    5

    96

    Returns: 362

  25. 48

    54

    87

    91

    Returns: 35

  26. 94

    99

    84

    84

    Returns: 6

  27. 70

    83

    11

    16

    Returns: 81

  28. 99

    99

    34

    77

    Returns: 44

  29. 51

    98

    37

    80

    Returns: 1823

  30. 75

    86

    90

    90

    Returns: 12

  31. 24

    31

    11

    14

    Returns: 30

  32. 71

    87

    61

    90

    Returns: 486

  33. 33

    93

    91

    100

    Returns: 593

  34. 15

    89

    66

    81

    Returns: 1125

  35. 27

    53

    27

    71

    Returns: 1035

  36. 69

    78

    26

    65

    Returns: 385

  37. 2

    3

    2

    3

    Returns: 3


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: