問題一覧 > 通常問題

No.643 Two Operations No.2

レベル : / AI推定難易度 : 900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 230
作問者 : Pulmn / テスター : rullonz
お気に入りにしたユーザー ProblemId : 1988 / 自分の提出
問題文最終更新日: 2026-06-29 11:47:25
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 182 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。