#B3925. Cat and Fish Distribution
Cat and Fish Distribution
Cat and Fish Distribution
There is a pile of fish on the beach that needs to be divided among N cats following a special process. The process is as follows:
Initially, there are X fish. The first cat divides the fish into N equal parts; however, there are \( i \) extra fish (with \( i < N \)). The cat discards these extra \( i \) fish into the sea and takes one of the equal parts. Then the second cat comes to divide the remaining fish into N equal parts. Again, there are exactly \( i \) extra fish, which are discarded, and the cat takes one part. This process continues with each of the N cats.
Mathematically, when a cat encounters \( f_j \) fish, we have: \[ f_j = N \times q_j + i \quad (0 \le i < N), \] The cat discards the extra \( i \) fish and takes one share of size \( q_j \), leaving: \[ f_{j+1} = (N-1) \times q_j. \] Each cat must get at least one fish, i.e. \( q_j \ge 1 \) for all steps.
Your task is to compute the minimum initial number of fish \( X = f_1 = N \times q_1 + i \) such that all N cats can follow this process and each gets fish.
Example: For N=2 and \( i=1 \), the minimum number of fish is 7. In this case, for the first cat, we have 7 fish which can be written as \(2 \times 3 + 1\); after discarding 1, 6 remain. The first cat takes 3 fish and leaves 3 for the second cat, which can be divided as \(2 \times 1 + 1\); after discarding 1, the second cat takes 1 fish.
Solve the problem and print the minimal number of fish.
inputFormat
The input consists of two integers separated by space:
- N: the number of cats.
- i: the number of extra fish discarded at each division (with 0 ≤ i < N).
For example: 2 1
outputFormat
Output a single integer which is the minimal initial number of fish on the beach such that each cat can get fish following the process described.
sample
2 1
7