forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeSmash.html
More file actions
8 lines (8 loc) · 5.49 KB
/
Copy pathCompositeSmash.html
File metadata and controls
8 lines (8 loc) · 5.49 KB
1
2
3
4
5
6
7
8
<html><body bgcolor="#cccccc" text="#000000"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>Toastwoman wants to be a magical girl. As training, she wants to make a ball that contains an integer <b>target</b>.
<br></br>
<br></br>
Initially she has a ball that contains an integer <b>N</b>. She can smash a ball that contains a composite number (see notes for definition) and break it into two balls. Each new ball will also contain an integer. If she smashes a ball that contains a composite number x and it breaks into two balls that contain y and z, it satisfies y &ge 2, z &ge 2 and yz = x. For example, if she smashes a ball that contains 12, it breaks into 2 and 6 or 3 and 4. Toastwoman can control the ball she smashes, but she can't control the numbers in the two new balls when there are multiple pairs of (y, z) that satisfy the above conditions. She can apply the described ball smash operation arbitrary number of times, but she can't smash a ball that contains a non-composite number.
<br></br>
<br></br>
If she can always make a ball that contains <b>target</b>, return "Yes" (quotes for clarity). Otherwise, return "No" (quotes for clarity).
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>CompositeSmash</td></tr><tr><td>Method:</td><td>thePossible</td></tr><tr><td>Parameters:</td><td>int, int</td></tr><tr><td>Returns:</td><td>string</td></tr><tr><td>Method signature:</td><td>string thePossible(int N, int target)</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>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>A positive integer x is called a <i>composite number</i> if it has at least one divisor other than 1 and x. For example, 4 and 6 are <i>composite numbers</i>, while 1 and 5 are not <i>composite numbers</i>.</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 2 and 100,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>target</b> will be between 2 and 100,000, 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>517</pre></td></tr><tr><td><pre>47</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Yes"</pre></td></tr><tr><td><table><tr><td colspan="2">If she smashes 517, it breaks into 11 and 47.</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>8</pre></td></tr><tr><td><pre>4</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Yes"</pre></td></tr><tr><td><table><tr><td colspan="2">If she smashes 8, it breaks into 2 and 4.</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>12</pre></td></tr><tr><td><pre>6</pre></td></tr></table></td></tr><tr><td><pre>Returns: "No"</pre></td></tr><tr><td><table><tr><td colspan="2">If she smashes 12 and it breaks into 3 and 4, she can't make 6.</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>5</pre></td></tr><tr><td><pre>8</pre></td></tr></table></td></tr><tr><td><pre>Returns: "No"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>100000</pre></td></tr><tr><td><pre>100000</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Yes"</pre></td></tr><tr><td><table><tr><td colspan="2">She already has <b>target</b>.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">5)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>5858</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: "Yes"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">6)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>81461</pre></td></tr><tr><td><pre>2809</pre></td></tr></table></td></tr><tr><td><pre>Returns: "No"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">7)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>65536</pre></td></tr><tr><td><pre>256</pre></td></tr></table></td></tr><tr><td><pre>Returns: "No"</pre></td></tr><tr><td></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>