Statistics

Problem Statement for "FleasFleas"

Problem Statement

My dog has fleas. I suspect that his fleas have fleas. I suspect that his fleas' fleas have fleas!

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

  1. 30

    7

    Returns: 660

    As described in the Problem Statement

  2. 100

    3

    Returns: 400

    There are 100 full-sized fleas, 3 of which have 100 tiny fleas each

  3. 100

    100

    Returns: -1

  4. 50

    15

    Returns: 45800

  5. 50

    14

    Returns: 32250

  6. 50

    24

    Returns: -1

  7. 100

    0

    Returns: 100

  8. 100

    1

    Returns: 200

  9. 100

    5

    Returns: 600

  10. 100

    6

    Returns: 1300

  11. 1

    0

    Returns: 1

  12. 1

    1

    Returns: 2

  13. 49

    24

    Returns: -1

  14. 49

    23

    Returns: 8724156

  15. 99

    10

    Returns: 6039

  16. 99

    9

    Returns: 4554

  17. 99

    11

    Returns: 14256

  18. 25

    25

    Returns: -1

  19. 25

    24

    Returns: 7353625

  20. 56

    23

    Returns: 9970464

  21. 2

    2

    Returns: 6

  22. 5

    5

    Returns: 30

  23. 58

    23

    Returns: -1

  24. 100

    99

    Returns: -1

  25. 100

    100

    Returns: -1

  26. 57

    23

    Returns: -1

  27. 56

    23

    Returns: 9970464

  28. 70

    30

    Returns: -1

  29. 70

    23

    Returns: -1


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: