Problem Statement
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
Returns: 1
Only the value 1/1 is being considered.
1
10
1
1
Returns: 10
Here S contains the values 1,...,10.
1
1
1
10
Returns: 10
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.
2
4
2
4
Returns: 7
1
100
1
100
Returns: 6087
67
74
81
85
Returns: 40
42
58
56
61
Returns: 99
5
40
7
73
Returns: 1575
85
97
25
70
Returns: 580
2
23
86
99
Returns: 299
15
82
91
93
Returns: 204
67
99
77
83
Returns: 225
20
29
11
67
Returns: 502
6
84
53
95
Returns: 2863
73
97
77
88
Returns: 287
83
95
66
90
Returns: 313
17
95
53
69
Returns: 1250
93
96
78
79
Returns: 8
46
93
30
99
Returns: 2794
24
82
85
90
Returns: 347
63
82
46
77
Returns: 594
73
95
57
78
Returns: 479
93
96
5
96
Returns: 362
48
54
87
91
Returns: 35
94
99
84
84
Returns: 6
70
83
11
16
Returns: 81
99
99
34
77
Returns: 44
51
98
37
80
Returns: 1823
75
86
90
90
Returns: 12
24
31
11
14
Returns: 30
71
87
61
90
Returns: 486
33
93
91
100
Returns: 593
15
89
66
81
Returns: 1125
27
53
27
71
Returns: 1035
69
78
26
65
Returns: 385
2
3
2
3
Returns: 3