No.3547 Rurumaru Function Problem
問題文最終更新日: 2026-04-22 21:41:51
English (AI translation)
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 500
(順位表)
の他の問題:
Problem Statement
For non-negative integers $x,y$, let $f(x,y)$ be the non-negative integer defined as follows.- In the binary representation of $f(x,y)$, the value of the $2^i(i \ge 0)$ place is:
- if $i$ is even, the logical AND of the value of the $2^i$ place of $x$ and the value of the $2^i$ place of $y$.
- if $i$ is odd, the logical OR of the value of the $2^i$ place of $x$ and the value of the $2^i$ place of $y$.
You are given non-negative integers $N,M$. Find the smallest non-negative integer $x$ such that $f(x, N)=M$.
If no such value exists, print -1.
Constraints
- $0 \le N \lt 2^{30}$
- $0 \le M \lt 2^{30}$
- All inputs are integers.
Input
$N\ M$
Output
Print the answer.
Sample
Sample 1
Input
31 14
Output
4$f(4, 31) = f(00100_{(2)}, 11111_{(2)})=01110_{(2)}=14$ holds, and no $x$ less than $4$ satisfies this, so print $4$.
Sample 2
Input
314 159
Output
-1
It can be proved that no non-negative integer $x$ satisfies this.
Therefore, print -1.
Sample 3
Input
1073741823 1073741823
Output
357913941
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ぽえ