#P16438. [XJTUPC 2026] 共同特征

    ID: 18469 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>数学数论最大公约数 gcd位运算2026高校校赛

[XJTUPC 2026] 共同特征

Problem Description

In computer science, bitwise AND (and⁡\operatorname{and}) is a binary operation. For any non-negative integers aa and bb, let their binary representations be a=∑i=0∞ai2ia = \sum_{i=0}^{\infty} a_i 2^i and b=∑i=0∞bi2ib = \sum_{i=0}^{\infty} b_i 2^i, where ai,bi∈{0,1}a_i, b_i \in \{0,1\} and only finitely many of them are non-zero. We define the result of the bitwise AND operation between aa and bb, denoted as aand⁡ba \operatorname{and} b, as:

$$a \operatorname{and} b = \sum_{i=0}^{\infty} (a_i \cdot b_i) 2^i$$

In mathematics, divisibility (∣\mid) is a binary relation. For any positive integers aa and bb, if and only if there exists a positive integer kk such that a=b⋅ka = b \cdot k, we say that bb divides aa, written as b∣ab\mid a.

In mathematics, the greatest common divisor (gcd⁡\gcd) is a binary operation. For any positive integers aa and bb, we define their greatest common divisor gcd⁡(a,b)\gcd(a,b) as the largest positive integer that divides both aa and b,i.e.b, i.e.:

$$\gcd(a, b) = \max\{ d \in \mathbb{N}^+ : d \mid a \wedge d \mid b \}$$

Now you are given a positive integer xx. Please find the smallest positive integer yy such that the result of the bitwise AND operation on xx and yy is equal to the greatest common divisor of xx and yy. That is, compute:

$$y_{\min} = \min\{ y \in \mathbb{N}^+ : (x \operatorname{and} y) = \gcd(x, y)\}$$

Input Format

This problem contains multiple test cases. The first line contains a positive integer TT (1≤T≤1051\le T\le 10^5), representing the number of test cases.

Next are the descriptions of TT test cases.

Each test case consists of one line containing a positive integer xx (1≤x<2601 \le x < 2^{60}).

Output Format

For each test case, output one line containing a positive integer ymin⁡y_{\min}, where $y_{\min} = \min\{ y \in \mathbb{N}^+ : (x \operatorname{and} y) = \gcd(x, y)\}$.

4
9
16
3108
56109
1
16
4
1

Hint

Translated by ChatGPT 5