forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountingSeries.html
More file actions
5 lines (5 loc) · 4.81 KB
/
Copy pathCountingSeries.html
File metadata and controls
5 lines (5 loc) · 4.81 KB
1
2
3
4
5
<html><body bgcolor="#cccccc" text="#000000"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>You are given long longs <b>a</b>, <b>b</b>, <b>c</b> and <b>d</b>. The numbers <b>a</b> and <b>b</b> define an arithmetic progression that consists of all numbers of the form <b>a</b> + <b>b</b>*x, where x is a nonnegative integer. Likewise, <b>c</b> and <b>d</b> define a geometric progression that consists of all the numbers that are equal to <b>c</b> * <b>d</b>^y, where y is a nonnegative integer. You are also given a long long <b>upperBound</b>. Return the total number of integers between 1 and <b>upperBound</b>, inclusive, that belong to the arithmetic progression, the geometric progression or both.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>CountingSeries</td></tr><tr><td>Method:</td><td>countThem</td></tr><tr><td>Parameters:</td><td>long long, long long, long long, long long, long long</td></tr><tr><td>Returns:</td><td>long long</td></tr><tr><td>Method signature:</td><td>long long countThem(long long a, long long b, long long c, long long d, long long upperBound)</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>The ^ operator in this statement denotes the exponentiation operation. For example, 3^0 = 1 and 2^4 = 2*2*2*2 = 16.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>a</b>, <b>b</b>, <b>c</b> and <b>upperBound</b> will each be between 1 and 1000000000000 (10^12), inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>d</b> will be between 1 and 100000 (10^5), 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>1</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>1000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1000</pre></td></tr><tr><td><table><tr><td colspan="2">The arithmetic progression is: 1, 2, 3, 4, ... .<br></br>
The geometric progression is: 1, 2, 4, 8, 16, ... .<br></br>
Each positive integer is contained in at least one of the progressions.</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>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>1000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 343</pre></td></tr><tr><td><table><tr><td colspan="2">This time, the arithmetic progression is: 3, 6, 9, 12, ... .<br></br>
The geometric progression is still: 1, 2, 4, 8, 16, ....<br></br>
There are 333 multiples of 3 between 1 and 1000, inclusive, and there are 10 powers of 2, 512 being the highest. As these two progressions do not have any common elements, the total result is 343.</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>40</pre></td></tr><tr><td><pre>77</pre></td></tr><tr><td><pre>40</pre></td></tr><tr><td><pre>100000</pre></td></tr><tr><td><pre>40</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</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>452</pre></td></tr><tr><td><pre>24</pre></td></tr><tr><td><pre>4</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>600</pre></td></tr></table></td></tr><tr><td><pre>Returns: 10</pre></td></tr><tr><td><table><tr><td colspan="2">The 10 numbers are: 4, 20, 100, 452, 476, 500, 524, 548, 572 and 596.</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>234</pre></td></tr><tr><td><pre>24</pre></td></tr><tr><td><pre>377</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>10000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 408</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>