forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockersDivOne.html
More file actions
5 lines (3 loc) · 2.86 KB
/
Copy pathLockersDivOne.html
File metadata and controls
5 lines (3 loc) · 2.86 KB
1
2
3
4
5
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>A hallway is filled with lockers numbered 1 through <b>N</b>, initially all closed. Out of boredom, Dave and Earl decide to open all the lockers. They make multiple passes through the hallway, each beginning at locker 1. On the first pass, they open the first unopened locker, and every second unopened locker thereafter. On the second pass, they open the first unopened locker, and every third unopened locker thereafter. In general, on the nth pass, they open the first unopened locker, and every (n+1)th unopened locker thereafter.</p>
<p>For example, with 9 lockers, on the first pass they open 1, 3, 5, 7, and 9, leaving 2, 4, 6, and 8. On the second pass they open 2 and 8, leaving 4 and 6. On the third pass they open locker 4, and on the final pass locker 6.</p>
<p>You will be given <b>N</b>, the number of lockers. Return the number of the locker opened last.</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>LockersDivOne</td></tr><tr><td>Method:</td><td>lastOpened</td></tr><tr><td>Parameters:</td><td>int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int lastOpened(int 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 2000000, 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>9</pre></td></tr></table></td></tr><tr><td><pre>Returns: 6</pre></td></tr><tr><td><table><tr><td colspan="2">The example from the problem statement.</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>42</pre></td></tr></table></td></tr><tr><td><pre>Returns: 42</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>314</pre></td></tr></table></td></tr><tr><td><pre>Returns: 282</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>