No.3498 Modulo Equation
Problem Statement
You are given positive integers $A,B$. Here, it is guaranteed that $A > B$.
Find the smallest positive integer $x$ such that the remainder when $x$ is divided by $A$ equals the remainder when $B$ is divided by $x$.
It can be proved that, under the constraints, at least one positive integer $x$ satisfying the condition exists, and moreover that its minimum value is at most $10^5$.
Constraints
- $1\le B < A \le 300$
- All inputs are integers
Input
The input is given from standard input in the following format.
$A\ B$
Output
Print on one line the minimum possible value of an integer satisfying the condition.
Sample
Sample 1
Input
5 3
Output
8
The remainder when $8$ is divided by $5$ and the remainder when $3$ is divided by $8$ are both $3$, so $x = 8$ satisfies the condition.
Also, it can be seen that $x = 1,2,3,4,5,6,7$ do not satisfy the condition. Therefore, the answer is $8$.
Sample 2
Input
31 4
Output
35
Sample 3
Input
202 6
Output
208
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Solalyth