409227: GYM103463 G LTS owns large quantities of apples

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. LTS owns large quantities of applestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

The difference between this problem and Hsueh- owns large quantities of apples is more than the data range, please read the statement carefully.

There are $$$n$$$ apples in ltslts's bag, and $$$m$$$ kids around the man. Let's numbered these children $$$1$$$ to $$$m$$$.

ltslts take all of the apples and gave to the first child.

  • The first child got $$$n$$$ apples from ltslts. Next, he ate an apple and the remaining apples could just be divided into $$$x$$$ piles. He took a single pile and gave the remaining ($$$x - 1$$$) piles to the second child.
  • The second child got $$$\displaystyle \frac{(n - 1)(x - 1)}{x}$$$ apples from the first child. Next, he ate an apple and the remaining apples could just be divided into $$$x$$$ piles. He took a single pile and gave the remaining ($$$x - 1$$$) piles to the third child.
  • $$$\cdots$$$
  • The $$$i$$$-th child got some apples from the ($$$i - 1$$$)-th child. Next, he ate an apple and the remaining apples could just be divided into $$$x$$$ piles. He took a single pile and gave the remaining ($$$x - 1$$$) piles to the ($$$i + 1$$$)-th child.
  • $$$\cdots$$$
  • The last child got some apples from the Penultimate child, Next, he ate an apple and the remaining apples could just be divided into $$$x$$$ piles. He took a single pile and go away.

It should be noted that the number of apples in a pile taken by last child must be a positive integer.

Until the last child go away, Hsueh- wants to know what is a valid $$$n$$$ that meets all requirements.

For instance, we consider $$$m = 2$$$ and $$$x = 3$$$, a valid answer is $$$n = 7$$$.

  • The first child got $$$7$$$ apples. Next, he ate an apple and the remaining $$$6$$$ apples could just be divided into $$$3$$$ piles and $$$2$$$ apples per pile. He took a single pile and gave the remaining $$$2$$$ piles to the second child.
  • The second child got $$$4$$$ apples. Next, he ate an apple and the remaining $$$3$$$ apples could just be divided into $$$3$$$ piles and $$$1$$$ apple per pile. He took a single pile and go away.
Input

The first line contains two integers $$$m(1 \leq m \leq 15)$$$ and $$$x(2 \leq x \leq 15)$$$, denoting the number of children and the number of piles in operation of each child.

Output

For each test case, print a single integer in one line: valid $$$n$$$ that meets all requirements.

We can show that an answer less than or equal to $$$10^{18}$$$ always exists. Therefore you should to print a valid $$$n$$$ less than or equal to $$$10^{18}$$$. If there are multiple answers, print any.

ExampleInput
2 3
Output
7

加入题单

上一题 下一题 算法标签: