問題一覧 > 通常問題

No.816 Beautiful tuples

レベル : / 実行時間制限 : 1ケース 1.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 236
作問者 : Enjapma_kyopro / テスター : ciel
お気に入りにしたユーザー ProblemId : 2343 / 自分の提出
問題文最終更新日: 2019-04-21 18:15:10
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 211 (順位表) の他の問題:

Problem Statement

In the Kingdom of Enjapma, there is a custom of giving a tuple of $3$ natural numbers to one's neighbors as a present.
A tuple of $3$ natural numbers is called a "beautiful tuple" when it satisfies the following $2$ conditions, where the tuple consists of those $3$ natural numbers.

Condition $1$. The $3$ numbers are pairwise distinct natural numbers (integers greater than or equal to $1$).
Condition $2$. The sum of any $2$ of the natural numbers is a multiple of the remaining $1$ number.

As a greeting upon entering the country, you have also decided to give a "beautiful tuple" to your neighbor.
You have $2$ natural numbers $A,B$. Output one value: the minimum $C$ such that the tuple $(A,B,C)$ is a "beautiful tuple".
If no such $C$ exists, output $-1$.
It can be proven that, under these constraints, if a solution exists, its value is at most $10^{18}$.

Input

$A$ $B$

$A$ and $B$ are integers
$1 \le A \le 10^9$
$1 \le B \le 10^9$
$A$ and $B$ are distinct

Output

Output the minimum $C$ such that the tuple $(A,B,C)$ is a "beautiful tuple".
If it does not exist, output $-1$.

Sample

Sample 1
Input
3 1
Output
2

The tuple $(3,1,2)$ satisfies condition $1$. Also,
$3+1$ is a multiple of $2$,
$3+2$ is a multiple of $1$,
$1+2$ is a multiple of $3$, so $(3,1,2)$ is a "beautiful tuple".
Also, $C = 1$ does not satisfy the conditions, so you should output $2$.

Sample 2
Input
4 1
Output
-1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。