#t107. 小猫分鱼
小猫分鱼
Cats Dividing the Fish
Problem Description
There is a pile of fish on the beach, and little cats come to divide it. The first cat splits the pile into equal parts, leaving fish over (); it throws those extra fish into the sea and takes away one part. The second cat then splits the remaining fish into equal parts, again leaving fish over, throws those fish into the sea, and takes away one part. The third, fourth, , and -th cats do the same: they split the final remaining fish into parts, throw away the extra fish, and take one part.
Write a program that reads the number of cats and the number of fish thrown into the sea each time, and outputs the minimum number of fish originally on the beach such that every cat can get its share.
For example, two cats divide the fish with , throwing away fish each time. To let every cat eat, we can assume the second cat needs to take fish, so there are fish to be divided before its turn; then before the first cat's turn there were fish.
Input Format
A total of lines. The first line contains an integer , the second line contains an integer .
It is guaranteed that and .
Output Format
One integer on a line, the minimum number of fish on the beach satisfying the requirement.
Sample Input
Sample Input 1
2
1
Sample Input 2
3
1
Sample Output
Sample Output 1
7
Sample Output 2
25
Sample Explanation
For sample 1, two cats divide the fish, throwing away fish each time. To let every cat eat, assume the second cat takes fish; then before its division there are fish remaining (split into parts with left over, throw away , take part). When the first cat divides, it is also split into parts with left over, so the total number of fish is .