Weird Function
Time limit0.1sMemory limit1024 MB
Given a positive integer a, find the largest gcd of (a XOR b) and (a AND b) over all b from 1 to a-1.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Math, Number theory
- Solved
- No attempts yet
Statement
You are given a positive integer . Choose an integer with so that the greatest common divisor of and is as large as possible, and print that value. In other words, find where Here is bitwise XOR and is bitwise AND. The operations on single bits are defined by the table below.
For longer numbers, the operation is applied to the binary digits of the two operands position by position, and the resulting bits form the answer in binary. For example, and , while and .
Input
The first line contains the number of queries (). Each of the next lines contains one integer ().
Output
Print lines. On line , print the value of .