#t107. 小猫分鱼

小猫分鱼

Cats Dividing the Fish

Problem Description

There is a pile of fish on the beach, and NN little cats come to divide it. The first cat splits the pile into NN equal parts, leaving ii fish over (i<Ni<N); it throws those extra ii fish into the sea and takes away one part. The second cat then splits the remaining fish into NN equal parts, again leaving ii fish over, throws those ii fish into the sea, and takes away one part. The third, fourth, …\dots, and NN-th cats do the same: they split the final remaining fish into NN parts, throw away the extra ii fish, and take one part.

Write a program that reads the number of cats NN and the number ii 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 N=2N=2, throwing away i=1i=1 fish each time. To let every cat eat, we can assume the second cat needs to take 11 fish, so there are 33 fish to be divided before its turn; then before the first cat's turn there were 3×2+1=73\times 2+1=7 fish.

Input Format

A total of 22 lines. The first line contains an integer NN, the second line contains an integer ii.

It is guaranteed that 0<N<100 < N < 10 and i<Ni < N.

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 11 fish each time. To let every cat eat, assume the second cat takes 11 fish; then before its division there are 33 fish remaining (split into 22 parts with 11 left over, throw away 11, take 11 part). When the first cat divides, it is also split into 22 parts with 11 left over, so the total number of fish is 3×2+1=73 \times 2 + 1 = 7.

Constraints

  • 0<N<100 < N < 10
  • i<Ni < N