Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2012 /quals /auction.html
wjomlex's picture
2012 Problems
91a79e0 verified
<p>You have encountered a new fancy online auction that offers lots of products.
You are only interested in their price and weight. We shall say that
product A is strictly preferred over product B if A costs less than B and is not
heavier (they may be of equal weight) or if A weighs less and is not more
expensive (they can have equal price).
</p>
<p>We shall call a product A a bargain if there is no product B such that B is
better than A. Similarly, we shall call a product C a terrible deal if there
exists no product D such that C is better than D. Note that according to our
definitions, the same product may be both a bargain and a terrible deal! Only
wacky auctioneers sell such products though.
</p>
<p>One day you wonder how many terrible deals and bargains are offered. The
number of products, N, is too large for your human-sized brain though.
Fortunately, you discovered that the auction manager is terribly lazy and
decided to sell the products based on a very simple pseudo-random number
generator.
</p>
<p>If product i has price P<sub>i</sub> and weight W<sub>i</sub>, then the
following holds for product i+1:
<ul>
<li> P<sub>i</sub> = ((A*P<sub>i-1</sub> + B) mod M) + 1 (for all i = 2..N)
<li> W<sub>i</sub> = ((C*W<sub>i-1</sub> + D) mod K) + 1 (for all i = 2..N)
</ul>
</p>
<p>You carefully calculated the parameters for the generator (P<sub>1</sub>,
W<sub>1</sub>, M, K, A, B, C and D). Now you want to calculate the
number of terrible deals and bargains on the site.
</p>
<h3>Input</h3>
<p>The first line of the input file contains a single integer T: the number of
test cases. T lines follow, each representing a single test case with
9 space-separated integers: N, P<sub>1</sub>, W<sub>1</sub>, M, K, A, B, C and
D.
</p>
<h3>Output</h3>
<p>Output T lines, one for each test case. For each case, output "Case #t: a b",
where t is the test case number (starting from 1), a is the number of terrible deals
and b is the number of bargains.
</p>
<h3>Constraints</h3>
<ul>
<li> 1 &le; T &le; 20
<li> 1 &le; N &le; 10<sup>18</sup>
<li> 1 &le; M, K &le; 10<sup>7</sup>
<li> 1 &le; P<sub>1</sub> &le; M
<li> 1 &le; W_1 &le; K
<li> 0 &le; A,B,C,D &le; 10<sup>9</sup>
</ul>