You have some bags of coins. Each bag contains exactly
coins. Exactly one bag
contains only counterfeit coins (we’ll call this the fake
bag), while all other bags contain only real coins. All
real coins weigh exactly the same number of grams. All
counterfeit coins weigh exactly the same number of grams. You
don’t know the exact weights of a real or counterfeit coin. You
do know a counterfeit coin is strictly heavier than a real
coin, but you do not know exactly how much heavier it is. The
weights of the coins are positive real numbers.
You have a scale which you can use at most times. The scale has a left and
right side. To use the scale, you can place any number of
coins, taken from any of the bags, on each side of the scale,
as long as the total number of coins on the left and right
sides are exactly equal. The scale will return a single real
number . If
is zero, both sides of
the scale weigh exactly the same. If is negative, the left side is
grams heavier than
the right side. If is
positive, the right side is grams heavier than the left side.
Coins can be reused multiple times for different weighings, and
you are able to keep track of which bag each coin came from.
You must specify beforehand all weighings you want to perform
(so you cannot adjust what gets weighed in future trials based
on the results of previous trials). After using the scale
times, you would like
to be able to determine which bag is the fake bag.
You are now wondering: given and , what is the maximum number of
bags for which you can always determine the fake bag? This
number can get large, so output it modulo the large prime
.
Input
The single line of input contains two space-separated
integers and
(), where
is the number of
weighings available to you and is the number of coins in each
bag.
Output
Output a single integer, which is the maximum number of bags
for which you can determine the fake bag in weighings, modulo the large prime
.
Sample Explanation
One way we can use
weighings to determine the fake bag among bags, each containing coin, is as follows:
-
On the first weighing, put the coins from bags
on the left,
and the coins from bags on the right.
-
On the second weighing, put the coins from bags
on the left,
and the coins from bags on the right.
We can determine the fake bag as follows:
-
The first weighing tells us which group of bags
,
,
contains the
fake bag (e.g. if the left side is heavier, then group
contains the
fake bag, if both sides are equal, then group contains the fake bag,
otherwise group contains the fake
bag).
-
The second weighing will tell us which group of bags
,
,
contains the
fake bag. The resulting fake bag can be uniquely determined
as a result.
Sample Input 1 |
Sample Output 1 |
2 1
|
9
|
Sample Input 2 |
Sample Output 2 |
2 2
|
17
|