Statistics

Problem Statement for "RedDragonInn"

Problem Statement

Red Dragon Inn is a board game in which the players' characters spend time in an inn brawling and drinking.


At any moment each character has some gold coins. If a character has "too much fun" during the game, they pass out. When that happens, the gold they have is divided between the inn and all other characters who are left standing. This works as follows:

  1. The inn takes half of the coins, rounded up to the nearest integer.
  2. The remaining coins, if any, are split evenly among the remaining characters.
  3. The remaining coins, if any, are taken by the inn again. (This occurs whenever in step 2 the number of coins isn't divisible by the number of players.)

A character just passed out. Let C be the number of coins they had. You do not know the value of C. You are given the int N: the number of characters who are still standing. You are also given the int X: the number of gold coins each of those characters received when the C coins were split between the inn and the players. Determine and return the largest possible value of C.

Definition

Class:
RedDragonInn
Method:
maxGold
Parameters:
int, int
Returns:
int
Method signature:
int maxGold(int N, int X)
(be sure your method is public)

Constraints

  • N will be between 2 and 100, inclusive.
  • X will be between 1 and 100,000, inclusive.

Examples

  1. 3

    2

    Returns: 17

    The process of dividing 17 coins between the inn and three characters looks as follows: First, the inn gets 9 coins (half of all coins, rounded up). Next, the remaining 8 coins are divided between the three characters. This means that each of them gets 2 coins (i.e., 8/3, rounded down). Finally, the inn takes the 2 coins that were left over. It can be shown that 17 is the largest initial amount of coins for which the players receive two coins each. For example, when dividing 18 coins the inn takes 9 and then each player takes 3.

  2. 8

    13

    Returns: 223

  3. 42

    1234

    Returns: 103739

  4. 2

    1

    Returns: 7

  5. 100

    100000

    Returns: 20000199

  6. 2

    99999

    Returns: 399999

  7. 99

    1

    Returns: 395

  8. 48

    520

    Returns: 50015

  9. 16

    6044

    Returns: 193439

  10. 5

    39306

    Returns: 393069

  11. 29

    989

    Returns: 57419

  12. 8

    98894

    Returns: 1582319

  13. 82

    34

    Returns: 5739

  14. 40

    70909

    Returns: 5672799

  15. 4

    50516

    Returns: 404135

  16. 85

    77015

    Returns: 13092719

  17. 46

    98417

    Returns: 9054455

  18. 90

    9

    Returns: 1799

  19. 43

    2730

    Returns: 234865

  20. 94

    73087

    Returns: 13740543

  21. 7

    41176

    Returns: 576477

  22. 11

    51856

    Returns: 1140853

  23. 74

    26990

    Returns: 3994667

  24. 51

    9788

    Returns: 998477

  25. 6

    7590

    Returns: 91091

  26. 67

    24356

    Returns: 3263837

  27. 15

    61632

    Returns: 1848989

  28. 40

    9533

    Returns: 762719

  29. 67

    70168

    Returns: 9402645

  30. 47

    80518

    Returns: 7568785

  31. 57

    63257

    Returns: 7211411

  32. 2

    69201

    Returns: 276807

  33. 91

    66651

    Returns: 12130663

  34. 18

    40348

    Returns: 1452563

  35. 57

    6650

    Returns: 758213

  36. 86

    75485

    Returns: 12983591

  37. 59

    29043

    Returns: 3427191

  38. 66

    43071

    Returns: 5685503

  39. 53

    337

    Returns: 35827

  40. 16

    43465

    Returns: 1390911

  41. 65

    34656

    Returns: 4505409

  42. 86

    1095

    Returns: 188511

  43. 10

    9999

    Returns: 199999


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: