Statistics

Problem Statement for "ThrowTheBall"

Problem Statement

There are N friends sitting in a circle, numbered clockwise in increasing order from 1 to N. At the beginning of the game, player 1 receives a ball. The players take turns passing the ball to each other. At the beginning of the game and before each next pass the following actions are performed. If the player with the ball has already received the ball M times, the game is over. Otherwise, if the player has received the ball p times, he'll pass the ball directly to the person L places to his left if p is even, or L places to his right if p is odd (see examples for clarification). Given N, M and L, return the number of times that the ball is passed.

Definition

Class:
ThrowTheBall
Method:
timesThrown
Parameters:
int, int, int
Returns:
int
Method signature:
int timesThrown(int N, int M, int L)
(be sure your method is public)

Constraints

  • N will be between 3 and 50, inclusive.
  • M will be between 1 and 50, inclusive.
  • L will be between 1 and N-1, inclusive.

Examples

  1. 5

    3

    2

    Returns: 10

    First, player 1 gets the ball. Since he has held the ball 1 time, he passes the ball to player 4, who is two places to his right. This is player 4's first time holding the ball, so he gives it to player 2, who passes it to player 5. Player 5 then passes the ball to player 3, who passes it back to player 1. Since player 1 has now held the ball 2 times, he passes it to player 3, who passes it to player 5, who then passes the ball to player 2. Finally, player 2 passes the ball to player 4, who then passes it to player 1. Player 1 has now held the ball 3 times, and the game ends.

  2. 4

    1

    3

    Returns: 0

    Here, the ball is never passed.

  3. 10

    3

    5

    Returns: 4

  4. 15

    4

    9

    Returns: 15

  5. 50

    50

    49

    Returns: 2450

  6. 50

    50

    1

    Returns: 2450

  7. 11

    50

    7

    Returns: 539

  8. 48

    2

    36

    Returns: 4

  9. 14

    1

    1

    Returns: 0

  10. 19

    23

    17

    Returns: 418

  11. 22

    22

    21

    Returns: 462

  12. 3

    50

    1

    Returns: 147

  13. 3

    50

    2

    Returns: 147

  14. 4

    50

    3

    Returns: 196

  15. 19

    49

    5

    Returns: 912

  16. 46

    5

    31

    Returns: 184

  17. 27

    15

    9

    Returns: 42

  18. 34

    21

    8

    Returns: 340

  19. 34

    32

    6

    Returns: 527

  20. 11

    50

    10

    Returns: 539

  21. 50

    50

    25

    Returns: 98

  22. 21

    13

    5

    Returns: 252

  23. 30

    43

    7

    Returns: 1260

  24. 48

    22

    17

    Returns: 1008

  25. 21

    16

    17

    Returns: 315

  26. 21

    28

    7

    Returns: 81

  27. 23

    17

    3

    Returns: 368

  28. 19

    46

    1

    Returns: 855

  29. 34

    7

    21

    Returns: 204

  30. 16

    42

    10

    Returns: 328

  31. 31

    17

    7

    Returns: 496

  32. 20

    44

    4

    Returns: 215

  33. 12

    31

    9

    Returns: 120

  34. 31

    7

    28

    Returns: 186

  35. 11

    1

    10

    Returns: 0

  36. 21

    44

    17

    Returns: 903

  37. 4

    23

    2

    Returns: 44

  38. 38

    27

    15

    Returns: 988

  39. 6

    39

    1

    Returns: 228

  40. 48

    47

    17

    Returns: 2208

  41. 18

    18

    10

    Returns: 153

  42. 29

    48

    21

    Returns: 1363

  43. 15

    40

    2

    Returns: 585

  44. 41

    32

    23

    Returns: 1271

  45. 26

    7

    9

    Returns: 156

  46. 34

    4

    1

    Returns: 102

  47. 9

    14

    7

    Returns: 117

  48. 21

    23

    17

    Returns: 462

  49. 32

    9

    18

    Returns: 128

  50. 10

    9

    4

    Returns: 40

  51. 16

    7

    13

    Returns: 96

  52. 9

    41

    6

    Returns: 120

  53. 14

    27

    3

    Returns: 364

  54. 9

    26

    2

    Returns: 225

  55. 15

    14

    13

    Returns: 195

  56. 18

    17

    14

    Returns: 144

  57. 42

    5

    20

    Returns: 84

  58. 25

    44

    2

    Returns: 1075

  59. 36

    29

    5

    Returns: 1008

  60. 43

    21

    5

    Returns: 860

  61. 15

    14

    8

    Returns: 195

  62. 42

    26

    40

    Returns: 525

  63. 4

    13

    3

    Returns: 48

  64. 29

    12

    17

    Returns: 319

  65. 32

    46

    31

    Returns: 1440

  66. 30

    29

    25

    Returns: 168

  67. 27

    38

    18

    Returns: 111

  68. 43

    45

    1

    Returns: 1892

  69. 48

    36

    30

    Returns: 280

  70. 30

    25

    4

    Returns: 360

  71. 44

    6

    8

    Returns: 55

  72. 11

    14

    5

    Returns: 143

  73. 33

    5

    6

    Returns: 44

  74. 22

    31

    21

    Returns: 660

  75. 46

    48

    12

    Returns: 1081

  76. 5

    25

    2

    Returns: 120

  77. 4

    33

    1

    Returns: 128

  78. 25

    18

    21

    Returns: 425

  79. 26

    16

    19

    Returns: 390

  80. 8

    8

    4

    Returns: 14

  81. 50

    50

    47

    Returns: 2450

  82. 50

    6

    2

    Returns: 125

  83. 3

    1

    1

    Returns: 0

  84. 5

    10

    1

    Returns: 45

  85. 6

    6

    5

    Returns: 30

  86. 42

    20

    41

    Returns: 798

  87. 5

    48

    2

    Returns: 235

  88. 7

    2

    3

    Returns: 7

  89. 4

    2

    2

    Returns: 2

  90. 49

    49

    7

    Returns: 336

  91. 50

    4

    9

    Returns: 150


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: