Statistics

Problem Statement for "NinjaTurtles"

Problem Statement

The Ninja Turtles often battle the Foot Clan ninjas. The Turtles celebrate each victory with a pizza party. The amount of pizza they eat depends on the number of opponents they have defeated. Denote the number of defeated opponents as N. Three of the four Turtles have a moderate appetite and only consume floor(N / K) pizzas each. The fourth Turtle is always hungry and eats floor(N / 3) pizzas.



You are given ints P and K, where P is the total number of pizzas the Turtles ate after a battle. If there exists at least one value of N such that after defeating N opponents the Turtles would eat exactly P pizzas at the party, return the smallest such N. Otherwise, return -1.

Definition

Class:
NinjaTurtles
Method:
countOpponents
Parameters:
int, int
Returns:
int
Method signature:
int countOpponents(int P, int K)
(be sure your method is public)

Notes

  • floor(X) is equal to the largest integer which is less or equal to X.

Constraints

  • P will be between 1 and 1,000,000, inclusive.
  • K will be between 4 and 100, inclusive.

Examples

  1. 5

    4

    Returns: 6

    If the Turtles defeated 6 opponents, three of the four Turtles would eat floor(6 / 4) = 1 pizza each and the fourth one would eat floor(6 / 3) = 2 pizzas, which makes 5 pizzas in total. Note that you always have to return the smallest possible N. For example, in this scenario for N = 7 the Turtles would also eat 5 pizzas, but 7 is not a correct return value, because 6 is less than 7.

  2. 1

    4

    Returns: 3

    After a fight with three opponents, only the hungry Turtle would eat a pizza.

  3. 13

    6

    Returns: -1

    There is no value of N such that if the Turtles battle N opponents, they eat exactly 13 pizzas for K = 6.

  4. 13

    17

    Returns: 30

    For K = 17, after defeating 30 opponents the Turtles will eat 13 pizzas in total.

  5. 122

    21

    Returns: 258

  6. 1000000

    100

    Returns: -1

  7. 1000000

    99

    Returns: 2750007

  8. 1000000

    98

    Returns: 2747667

  9. 999999

    100

    Returns: 2752299

  10. 1000000

    4

    Returns: 923079

  11. 112

    8

    Returns: -1

  12. 113

    8

    Returns: 160

  13. 114

    8

    Returns: 162

  14. 1

    100

    Returns: 3

  15. 666

    66

    Returns: 1764

  16. 1234

    4

    Returns: -1

  17. 12345

    4

    Returns: 11396

  18. 8462

    26

    Returns: 18861

  19. 983325

    59

    Returns: 2559538

  20. 93135

    100

    Returns: 256338

  21. 69993

    22

    Returns: 149022

  22. 69994

    22

    Returns: 149025

  23. 69994

    11

    Returns: 115491

  24. 903

    8

    Returns: 1278

  25. 903

    4

    Returns: -1

  26. 905

    4

    Returns: 836

  27. 20000

    6

    Returns: 24000

  28. 20005

    6

    Returns: 24006

  29. 555555

    55

    Returns: 1432296

  30. 52951

    92

    Returns: 144705

  31. 52951

    96

    Returns: 145245

  32. 52952

    96

    Returns: -1

  33. 909090

    90

    Returns: 2479338

  34. 909090

    95

    Returns: 2491263

  35. 909090

    100

    Returns: 2502090

  36. 44

    11

    Returns: -1

  37. 44

    21

    Returns: 96

  38. 4400

    5

    Returns: 4715

  39. 3912

    79

    Returns: 10539

  40. 100000

    4

    Returns: 92308

  41. 100000

    5

    Returns: -1

  42. 1000000

    51

    Returns: 2550000

  43. 1000000

    7

    Returns: 1312500

  44. 602408

    7

    Returns: -1

  45. 602408

    9

    Returns: 903615

  46. 293852

    40

    Returns: -1

  47. 293852

    41

    Returns: 722877

  48. 512000

    32

    Returns: 1198833

  49. 709222

    88

    Returns: 1930260

  50. 512512

    64

    Returns: 1347978

  51. 80000

    67

    Returns: -1

  52. 82000

    67

    Returns: 216876

  53. 82222

    83

    Returns: 222537

  54. 400000

    6

    Returns: 480000

  55. 400000

    5

    Returns: 428574

  56. 400001

    4

    Returns: 369232

  57. 659554

    100

    Returns: 1815294

  58. 878342

    36

    Returns: 2108022

  59. 65281

    59

    Returns: 169923

  60. 2512

    4

    Returns: -1

  61. 4

    4

    Returns: 4

  62. 13

    4

    Returns: 12

  63. 1355

    4

    Returns: -1

  64. 2358

    4

    Returns: 2178

  65. 999999

    4

    Returns: 923076

  66. 999997

    41

    Returns: -1

  67. 999997

    42

    Returns: 2470584

  68. 605553

    100

    Returns: 1666665

  69. 763000

    100

    Returns: 2100000

  70. 726666

    100

    Returns: 2000000

  71. 10000

    4

    Returns: -1

  72. 999999

    99

    Returns: 2750004

  73. 100

    50

    Returns: 255

  74. 1000000

    25

    Returns: 2205885

  75. 2

    8

    Returns: 6

  76. 790000

    70

    Returns: 2100000

  77. 1000000

    21

    Returns: 2100000

  78. 1000000

    50

    Returns: 2542377

  79. 399666

    100

    Returns: 1100000

  80. 460000

    30

    Returns: 1061544

  81. 999875

    35

    Returns: 2386068

  82. 676666

    100

    Returns: 1862391

  83. 1000000

    14

    Returns: -1

  84. 1000000

    95

    Returns: 2740386

  85. 1000000

    6

    Returns: 1200000

  86. 1000000

    11

    Returns: 1650000

  87. 999920

    100

    Returns: 2752080

  88. 696666

    10

    Returns: 1100000

  89. 2

    4

    Returns: -1

  90. 1000000

    23

    Returns: 2156250

  91. 1000000

    15

    Returns: 1875000

  92. 1000000

    40

    Returns: 2448984

  93. 437

    4

    Returns: 404

  94. 1000000

    86

    Returns: -1

  95. 833335

    6

    Returns: 1000002

  96. 1000000

    12

    Returns: 1714287

  97. 1000000

    91

    Returns: 2730000

  98. 1000000

    20

    Returns: 2068968

  99. 833355

    6

    Returns: 1000026

  100. 119166

    4

    Returns: 110000

  101. 14

    5

    Returns: 15

  102. 686667

    100

    Returns: 1889910

  103. 300000

    100

    Returns: 825696

  104. 999990

    100

    Returns: 2752272


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: