問題一覧 > 通常問題

No.3547 Rurumaru Function Problem

レベル : / AI推定難易度 : 425 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 72
作問者 : ルク / テスター : 👑 loop0919 ぽえ
お気に入りにしたユーザー ProblemId : 13327 / 自分の提出
問題文最終更新日: 2026-04-22 21:41:51
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$.
For example, $f(2,14)=10$. (In binary, this is $f(0010_{(2)},1110_{(2)})=1010_{(2)}$.)

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