forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheNumberGameDivOne.html
More file actions
26 lines (24 loc) · 3.78 KB
/
Copy pathTheNumberGameDivOne.html
File metadata and controls
26 lines (24 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>John and Brus play a game with a number.
The game starts with a positive integer <b>n</b>.
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.
<br></br><br></br>
For example, if they start with <b>n</b>=15, one possible gameplay can look as follows:
<ul>
<li>John takes the number 15, chooses its divisor 3, and decreases the number to 15-3 = 12.</li>
<li>Brus takes the number 12, chooses its divisor 4, and decreases the number to 12-4 = 8.</li>
<li>John takes the number 8, chooses its divisor 2, and decreases the number to 8-2 = 6.</li>
<li>Brus takes the number 6, chooses its divisor 3, and decreases the number to 6-3 = 3.</li>
<li>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.</li>
</ul>
<br></br><br></br>
You are given the long long <b>n</b>.
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.
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>TheNumberGameDivOne</td></tr><tr><td>Method:</td><td>find</td></tr><tr><td>Parameters:</td><td>long long</td></tr><tr><td>Returns:</td><td>string</td></tr><tr><td>Method signature:</td><td>string find(long long n)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>n</b> will be between 1 and 10^18, inclusive.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>6</pre></td></tr></table></td></tr><tr><td><pre>Returns: "John"</pre></td></tr><tr><td><table><tr><td colspan="2">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.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Brus"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>747</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Brus"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>128</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Brus"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr></table><p>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)2003, TopCoder, Inc. All rights reserved. </p></body></html>