#P16438. [XJTUPC 2026] 共同特征
[XJTUPC 2026] 共同特征
Problem Description
In computer science, bitwise AND () is a binary operation. For any non-negative integers and , let their binary representations be and , where and only finitely many of them are non-zero. We define the result of the bitwise AND operation between and , denoted as , as:
$$a \operatorname{and} b = \sum_{i=0}^{\infty} (a_i \cdot b_i) 2^i$$In mathematics, divisibility () is a binary relation. For any positive integers and , if and only if there exists a positive integer such that , we say that divides , written as .
In mathematics, the greatest common divisor () is a binary operation. For any positive integers and , we define their greatest common divisor as the largest positive integer that divides both and :
$$\gcd(a, b) = \max\{ d \in \mathbb{N}^+ : d \mid a \wedge d \mid b \}$$Now you are given a positive integer . Please find the smallest positive integer such that the result of the bitwise AND operation on and is equal to the greatest common divisor of and . 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 (), representing the number of test cases.
Next are the descriptions of test cases.
Each test case consists of one line containing a positive integer ().
Output Format
For each test case, output one line containing a positive integer , 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