Statistics

Problem Statement for "TheNumberGameDivTwo"

Problem Statement

John and Brus play a game with a number. The game starts with a positive integer n. The two players take alternating turns, John starts. Each move looks as follows: Let C be the current value of the integer. The current player has to choose a positive divisor of the number C, other than 1 and C. Once he chooses the divisor, he has to subtract it from C. The result is the new number with which the other player now starts his move. If a player cannot make a valid move, he loses the game.

For example, if they start with n=15, one possible gameplay can look as follows:
  • John takes the number 15, chooses its divisor 3, and decreases the number to 15-3 = 12.
  • Brus takes the number 12, chooses its divisor 4, and decreases the number to 12-4 = 8.
  • John takes the number 8, chooses its divisor 2, and decreases the number to 8-2 = 6.
  • Brus takes the number 6, chooses its divisor 3, and decreases the number to 6-3 = 3.
  • John takes the number 3, and as there are no divisors other than 1 and 3, he has no valid move and thus he loses the game.


You are given the int n. Assume that both players use the optimal strategy while playing the game. Return "John" (quotes for clarity) if John wins the game and "Brus" otherwise.

Definition

Class:
TheNumberGameDivTwo
Method:
find
Parameters:
int
Returns:
String
Method signature:
String find(int n)
(be sure your method is public)

Constraints

  • n will be between 1 and 1000, inclusive.

Examples

  1. 6

    Returns: "John"

    John has two possible moves: either decrease 6 by 2 or decrease 6 by 3. If he chooses the second option, Brus will have no possible moves, hence John will win the game.

  2. 2

    Returns: "Brus"

  3. 747

    Returns: "Brus"

  4. 128

    Returns: "Brus"

  5. 417

    Returns: "Brus"

  6. 223

    Returns: "Brus"

  7. 52

    Returns: "John"

  8. 483

    Returns: "Brus"

  9. 64

    Returns: "John"

  10. 488

    Returns: "John"

  11. 462

    Returns: "John"

  12. 778

    Returns: "John"

  13. 597

    Returns: "Brus"

  14. 556

    Returns: "John"

  15. 65

    Returns: "Brus"

  16. 231

    Returns: "Brus"

  17. 199

    Returns: "Brus"

  18. 992

    Returns: "John"

  19. 257

    Returns: "Brus"

  20. 830

    Returns: "John"

  21. 396

    Returns: "John"

  22. 469

    Returns: "Brus"

  23. 276

    Returns: "John"

  24. 802

    Returns: "John"

  25. 914

    Returns: "John"

  26. 543

    Returns: "Brus"

  27. 631

    Returns: "Brus"

  28. 45

    Returns: "Brus"

  29. 837

    Returns: "Brus"

  30. 860

    Returns: "John"

  31. 533

    Returns: "Brus"

  32. 373

    Returns: "Brus"

  33. 367

    Returns: "Brus"

  34. 259

    Returns: "Brus"

  35. 394

    Returns: "John"

  36. 16

    Returns: "John"

  37. 32

    Returns: "Brus"

  38. 256

    Returns: "John"

  39. 512

    Returns: "Brus"

  40. 64

    Returns: "John"

  41. 8

    Returns: "Brus"

  42. 5

    Returns: "Brus"

  43. 4

    Returns: "John"

  44. 3

    Returns: "Brus"

  45. 1

    Returns: "Brus"

  46. 999

    Returns: "Brus"

  47. 1000

    Returns: "John"

  48. 124

    Returns: "John"

  49. 12

    Returns: "John"

  50. 348

    Returns: "John"

  51. 578

    Returns: "John"

  52. 10

    Returns: "John"

  53. 9

    Returns: "Brus"

  54. 875

    Returns: "Brus"

  55. 843

    Returns: "Brus"

  56. 15

    Returns: "Brus"

  57. 20

    Returns: "John"

  58. 644

    Returns: "John"

  59. 478

    Returns: "John"

  60. 786

    Returns: "John"

  61. 21

    Returns: "Brus"

  62. 60

    Returns: "John"

  63. 888

    Returns: "John"

  64. 900

    Returns: "John"

  65. 840

    Returns: "John"

  66. 18

    Returns: "John"

  67. 159

    Returns: "Brus"

  68. 28

    Returns: "John"

  69. 132

    Returns: "John"


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: