Problem Statement
Assume that every infested creature (either a dog or a flea) is infested with n fleas and that k of these are themselves infested (with smaller fleas). At each smaller size, n stays the same but k decreases by 5 (but never becomes negative).
For example, suppose that n is 30 and k is originally 7. Then my dog is infested by 30 fleas of which 7 are infested with tiny fleas. Each of those 7 is infested with 30 tiny fleas of which 2 are infested with 30 miniscule fleas. No miniscule flea is infested (since 2-5 is not positive). Calculating the entire population we get 23 uninfested fleas + 7 infested fleas + 196 uninfested tiny fleas + 14 infested tiny fleas + 420 minuscule uninfested fleas = 660 fleas of all sizes.
Create a class FleasFleas that contains method population that takes an int n, the number of full-sized fleas on my dog, and an int k, the number of those that are themselves infested, and returns the total flea population on my dog. If the population is more than 10,000,000 return -1.
Definition
- Class:
- FleasFleas
- Method:
- population
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int population(int n, int k)
- (be sure your method is public)
Constraints
- n is between 1 and 100 inclusive
- k is between 0 and n inclusive
Examples
30
7
Returns: 660
As described in the Problem Statement
100
3
Returns: 400
There are 100 full-sized fleas, 3 of which have 100 tiny fleas each
100
100
Returns: -1
50
15
Returns: 45800
50
14
Returns: 32250
50
24
Returns: -1
100
0
Returns: 100
100
1
Returns: 200
100
5
Returns: 600
100
6
Returns: 1300
1
0
Returns: 1
1
1
Returns: 2
49
24
Returns: -1
49
23
Returns: 8724156
99
10
Returns: 6039
99
9
Returns: 4554
99
11
Returns: 14256
25
25
Returns: -1
25
24
Returns: 7353625
56
23
Returns: 9970464
2
2
Returns: 6
5
5
Returns: 30
58
23
Returns: -1
100
99
Returns: -1
100
100
Returns: -1
57
23
Returns: -1
56
23
Returns: 9970464
70
30
Returns: -1
70
23
Returns: -1