Statistics

Problem Statement for "ChooseTheBestOne"

Problem Statement

Shiny wants to give an award to one of the employees in her company. However, all her employees are doing perfect work, so it's hard to pick the one that gets the award. Therefore Shiny organized a game they will play to determine the winner.


At the beginning of the game, all N employees form a circle. Then, they receive t-shirts with numbers 1 through N in clockwise order along the circle. These numbers are never used in the game, we will just use them to identify the winner.


The game is played in turns. The turns are numbered starting from 1. In each turn, Shiny starts by standing in front of some employee (as specified below) and saying "one". Then she moves clockwise along the circle to the next employee and says "two". And so on, until the number she says reaches the threshold for that particular turn. The threshold for turn number t is t^3. (That is, the threshold is 1 for turn 1, 8 for turn 2, 27 for turn 3, and so on.)


At the end of each turn, the employee currently standing in front of Shiny (i.e., the one that received the number t^3) is eliminated. In the very first round Shiny starts in front of the employee with the number 1 on their t-shirt. In each of the following rounds, Shiny starts in front of the next employee clockwise from the one who just got eliminated.


When there is only one employee left in the game, the game ends and the employee wins the award.


You are given the int N. Return the t-shirt number of the employee who gets the award.

Definition

Class:
ChooseTheBestOne
Method:
countNumber
Parameters:
int
Returns:
int
Method signature:
int countNumber(int N)
(be sure your method is public)

Constraints

  • N will between 1 and 5000, inclusive.

Examples

  1. 3

    Returns: 2

    In the first round, Shiny stands in front of employee 1, says "one" and eliminates him. In the second round, Shiny starts in front of employee 2. She says "one" to employee 2, "two" to employee 3, "three" to employee 2 again, ..., and "eight" to employee 3. Thus, employee 3 gets eliminated and employee 2 wins the award.

  2. 6

    Returns: 6

  3. 10

    Returns: 8

  4. 1234

    Returns: 341

  5. 2414

    Returns: 1368

  6. 1506

    Returns: 767

  7. 1113

    Returns: 405

  8. 2462

    Returns: 1286

  9. 3423

    Returns: 1635

  10. 3647

    Returns: 1386

  11. 2172

    Returns: 833

  12. 2065

    Returns: 1520

  13. 2749

    Returns: 299

  14. 1756

    Returns: 732

  15. 2471

    Returns: 583

  16. 1840

    Returns: 551

  17. 2577

    Returns: 42

  18. 2293

    Returns: 1389

  19. 2201

    Returns: 1070

  20. 1839

    Returns: 1618

  21. 120

    Returns: 32

  22. 3522

    Returns: 818

  23. 2078

    Returns: 1283

  24. 657

    Returns: 208

  25. 1421

    Returns: 634

  26. 2040

    Returns: 276

  27. 1660

    Returns: 776

  28. 1366

    Returns: 499

  29. 201

    Returns: 117

  30. 4887

    Returns: 2687

  31. 1780

    Returns: 654

  32. 2056

    Returns: 87

  33. 1090

    Returns: 158

  34. 996

    Returns: 706

  35. 612

    Returns: 72

  36. 1298

    Returns: 806

  37. 1650

    Returns: 1526

  38. 1634

    Returns: 1108

  39. 2899

    Returns: 2654

  40. 2306

    Returns: 250

  41. 1369

    Returns: 997

  42. 1261

    Returns: 482

  43. 3396

    Returns: 615

  44. 2793

    Returns: 1289

  45. 2566

    Returns: 1583

  46. 2856

    Returns: 2210

  47. 3607

    Returns: 2681

  48. 1080

    Returns: 380

  49. 2626

    Returns: 112

  50. 4207

    Returns: 923

  51. 2852

    Returns: 2549

  52. 2525

    Returns: 2112

  53. 2349

    Returns: 587

  54. 3063

    Returns: 2587

  55. 3306

    Returns: 2580

  56. 1902

    Returns: 1770

  57. 2141

    Returns: 1195

  58. 2637

    Returns: 2533

  59. 559

    Returns: 189

  60. 3037

    Returns: 228

  61. 3588

    Returns: 3478

  62. 4916

    Returns: 1508

  63. 4888

    Returns: 2755

  64. 1781

    Returns: 1471

  65. 929

    Returns: 662

  66. 867

    Returns: 813

  67. 2643

    Returns: 1740

  68. 1028

    Returns: 482

  69. 498

    Returns: 112

  70. 62

    Returns: 17

  71. 1235

    Returns: 606

  72. 386

    Returns: 89

  73. 3801

    Returns: 835

  74. 611

    Returns: 482

  75. 3748

    Returns: 1886

  76. 1433

    Returns: 733

  77. 612

    Returns: 72

  78. 56

    Returns: 20

  79. 2280

    Returns: 1986

  80. 101

    Returns: 12

  81. 3834

    Returns: 2837

  82. 4884

    Returns: 40

  83. 4338

    Returns: 45

  84. 2205

    Returns: 900

  85. 1

    Returns: 1

  86. 2

    Returns: 2

  87. 5000

    Returns: 4200

  88. 4999

    Returns: 1656

  89. 4000

    Returns: 1680

  90. 842

    Returns: 140

  91. 1765

    Returns: 45

  92. 4894

    Returns: 2035


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: