#7641. [VKOSHP 2025] System of Equations with XOR

[VKOSHP 2025] System of Equations with XOR

[VKOSHP 2025] System of Equations with XOR

题目描述

Alice and Bob love problems involving random numbers. One day they came up with the following problem:
  • First, Alice chooses a random integer xx from the range of 11 to 231−12^{31} - 1, all numbers are equally likely.
  • Then, Bob chooses a random integer yy from the range of 11 to 231−12^{31} - 1, all numbers are equally likely.
  • They calculate the product of these numbers a=x⋅ya = x \cdot y and their bitwise XOR b=x⊕yb = x \oplus y.

You are given two resulting integers aa and bb. Find any pair of natural numbers xx and yy such that:

xy=aandx⊕y=b,xy = a \quad \text{and} \quad x \oplus y = b,

where ⊕\oplus denotes the bitwise XOR operation.

Recall that the bitwise "exclusive or" (⊕\oplus, xor) of two non-negative integers is defined as follows: write both numbers in binary representation; the ii-th binary digit of the result is 1 if exactly one of the arguments has it equal to 1. For example, (1414 xor 77) = (11102⊕011121110_2 \oplus 0111_2) = 100121001_2 = 99.

输入格式

The first line of the input contains a single integer $t$ $(1 \leq t \leq 200\,000)$ --- the number of test cases.

In the following tt lines of input, there are two integers aa and bb (1≤a<2621 \leq a < 2^{62}, 0≤b<2310 \leq b < 2^{31}) --- the description of the next test case.

输出格式

For each test case, output in a separate line two natural numbers $x$ and $y$, separated by a space, such that $xy = a$ and $x \oplus y = b$.

If there are multiple valid answers, you may output any of them.

2
21 4
9 0
7 3
3 3

提示

In this problem, there are $100$ tests, including the example from the statement. It is guaranteed that in all tests, except for the example from the statement, $t = 200\,000$, and the numbers $a$ and $b$ for each test case were generated by choosing random numbers $x$ and $y$ by Alice and Bob. 标签: P15318|2025|Special Judge

来源

P15318|[VKOSHP 2025] System of Equations with XOR