No.816 Beautiful tuples
タグ : / 解いたユーザー数 236
作問者 :
Enjapma_kyopro
/ テスター :
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もしくは右上の雲マークをクリックしてアカウントを作成してください。