D. Plus and xor

Codeforces
IDCF76D
Time2000ms
Memory256MB
Difficulty
dpgreedymath
English · Original
Chinese · Translation
Formal · Original
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different. For example, if _X_ = 10910 = 11011012, _Y_ = 4110 = 1010012, then: <center>_X_ _xor_ _Y_  =  6810  =  10001002.</center>Write a program, which takes two non-negative integers _A_ and _B_ as an input and finds two non-negative integers _X_ and _Y_, which satisfy the following conditions: * _A_ = _X_ + _Y_ * _B_  =  _X_ _xor_ _Y_, where _xor_ is bitwise exclusive or. * _X_ is the smallest number among all numbers for which the first two conditions are true. ## Input The first line contains integer number _A_ and the second line contains integer number _B_ (0 ≤ _A_, _B_ ≤ 264 - 1). ## Output The only output line should contain two integer non-negative numbers _X_ and _Y_. Print the only number _\-1_ if there is no answer. [samples]
按位异或(或按位模二加法)是一种二元运算,它等价于对操作数二进制表示中相同位置的每一位应用逻辑异或。换句话说,结果的二进制位等于 1,当且仅当操作数中对应位置的位不同。 例如,若 #cf_span[X = 10910 = 11011012], #cf_span[Y = 4110 = 1010012],则: 编写一个程序,输入两个非负整数 #cf_span[A] 和 #cf_span[B],找出两个非负整数 #cf_span[X] 和 #cf_span[Y],满足以下条件: 第一行包含整数 #cf_span[A],第二行包含整数 #cf_span[B](#cf_span[0 ≤ A, B ≤ 264 - 1])。 输出仅一行,包含两个非负整数 #cf_span[X] 和 #cf_span[Y]。若无解,请仅输出 _-1_。 ## Input 第一行包含整数 #cf_span[A],第二行包含整数 #cf_span[B](#cf_span[0 ≤ A, B ≤ 264 - 1])。 ## Output 输出仅一行,包含两个非负整数 #cf_span[X] 和 #cf_span[Y]。若无解,请仅输出 _-1_。 [samples]
**Definitions** Let $ A, B \in \mathbb{Z}_{\geq 0} $ with $ 0 \leq A, B \leq 2^{64} - 1 $. We seek $ X, Y \in \mathbb{Z}_{\geq 0} $ such that: $$ X + Y = A \quad \text{and} \quad X \oplus Y = B $$ where $ \oplus $ denotes bitwise XOR. **Constraints** 1. $ 0 \leq A, B \leq 2^{64} - 1 $ 2. $ X, Y \geq 0 $ **Objective** Find $ X, Y \in \mathbb{Z}_{\geq 0} $ satisfying: $$ X + Y = A \quad \text{and} \quad X \oplus Y = B $$ If no such pair exists, output $-1$.
Samples
Input #1
142
76
Output #1
33 109
API Response (JSON)
{
  "problem": {
    "name": "D. Plus and xor",
    "description": {
      "content": "Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF76D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "按位异或(或按位模二加法)是一种二元运算,它等价于对操作数二进制表示中相同位置的每一位应用逻辑异或。换句话说,结果的二进制位等于 1,当且仅当操作数中对应位置的位不同。\n\n例如,若 #cf_span[X = 10910 = 11011012], #cf_span[Y = 4110 = 1010012],则:\n\n编写一个程序,输入两个非负整数 #cf_span[A] 和 #cf_span[B],找出...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ A, B \\in \\mathbb{Z}_{\\geq 0} $ with $ 0 \\leq A, B \\leq 2^{64} - 1 $.  \nWe seek $ X, Y \\in \\mathbb{Z}_{\\geq 0} $ such that:  \n$$\nX + Y = A \\quad \\text{and} \\quad X \\oplus Y = B\n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments