No.643 Two Operations No.2
Problem Statement
You have $2$ integers $X,Y$, and you may perform the following $2$ operations any number of times in any order. Find the minimum number of operations required to make the values of $X$ and $Y$ equal. If it is impossible, output $-1$.
Let $X',Y'$ denote the values of $X,Y$ after an operation, respectively.
Operation 1: $X'=Y$ $,$ $Y'=X$
Operation 2: $X'=X+Y$ $,$ $Y'=X-Y$
Input
$X$ $Y$
$-100\le X,Y\le 100$
Output
Find the minimum number of operations required to make the values of $X$ and $Y$ equal. If it is impossible, output $-1
$. Print a newline at the end.
Sample
Sample 1
Input
0 2
Output
2
By performing Operation 1 $\rightarrow$ Operation 2 in this order, you can make $X=Y$. The values of $(X,Y)$ change as follows.
$(0,2)\rightarrow (2,0)\rightarrow (2,2)$
Sample 2
Input
-2 -2
Output
0
There are cases where no operation is needed.
Sample 3
Input
-100 99
Output
-1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Pulmn
rullonz