Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.

Suppose you are given a positive integer $a$. You want to choose some integer $b$ from $1$ to $a - 1$ inclusive in such a way that the greatest common divisor (GCD) of integers $a \oplus b$ and $a \> \& \> b$ is as large as possible. In other words, you'd like to compute the following function:

$$f(a) = \max_{0 < b < a}{gcd(a \oplus b, a \> \& \> b)}.$$

Here $\oplus$ denotes the bitwise XOR operation, and $\&$ denotes the bitwise AND operation.

The greatest common divisor of two integers $x$ and $y$ is the largest integer $g$ such that both $x$ and $y$ are divided by $g$ without remainder.

You are given $q$ integers $a_1, a_2, \ldots, a_q$. For each of these integers compute the largest possible value of the greatest common divisor (when $b$ is chosen optimally). 


-----Input-----

The first line contains an integer $q$ ($1 \le q \le 10^3$) — the number of integers you need to compute the answer for.

After that $q$ integers are given, one per line: $a_1, a_2, \ldots, a_q$ ($2 \le a_i \le 2^{25} - 1$) — the integers you need to compute the answer for. 


-----Output-----

For each integer, print the answer in the same order as the integers are given in input.


-----Example-----
Input
3
2
3
5

Output
3
1
7



-----Note-----

For the first integer the optimal choice is $b = 1$, then $a \oplus b = 3$, $a \> \& \> b = 0$, and the greatest common divisor of $3$ and $0$ is $3$.

For the second integer one optimal choice is $b = 2$, then $a \oplus b = 1$, $a \> \& \> b = 2$, and the greatest common divisor of $1$ and $2$ is $1$.

For the third integer the optimal choice is $b = 2$, then $a \oplus b = 7$, $a \> \& \> b = 0$, and the greatest common divisor of $7$ and $0$ is $7$.

Source: codeforces | Difficulty: MEDIUM
Tags: Number theory

Mathematics

Constructive algorithms


Solutions:
q = int(input())
for o in range(q):
	a = int(input())
	s = bin(a).replace('0b', '')
	flag = 0
	for c in s:
		if c == '0':
			flag = 1
			break
	if flag == 1:
		print(pow(2, len(s)) - 1)
	elif a == 3:
		print(1)
	elif a == 7:
		print(1)
	elif a == 15:
		print(5)
	elif a == 31:
		print(1)
	elif a == 63:
		print(21)
	elif a == 127:
		print(1)
	elif a == 255:
		print(85)
	elif a == 511:
		print(73)
	elif a == 1023:
		print(341)
	elif a == 2047:
		print(89)
	elif a == 4095:
		print(1365)
	elif a == 8191:
		print(1)
	elif a == 16383:
		print(5461)
	elif a == 32767:
		print(4681)
	elif a == 65535:
		print(21845)
	elif a == 131071:
		print(1)
	elif a == 262143:
		print(87381)
	elif a == 524287:
		print(1)
	elif a == 1048575:
		print(349525)
	elif a == 2097151:
		print(299593)
	elif a == 4194303:
		print(1398101)
	elif a == 8388607:
		print(178481)
	elif a == 16777215:
		print(5592405)
	elif a == 33554431:
		print(1082401)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def modu(a, m):
	if a % m:
		return a % m
	return m

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return 1
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return 1

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def binsearch(arr, b, low, high):
	if low == high:
		return low
	if arr[math.ceil((low + high) / 2)] < b:
		return binsearch(arr, b, low, math.ceil((low + high) / 2) - 1)
	else:
		return binsearch(arr, b, math.ceil((low + high) / 2), high)

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s

def calc(n, m, r):
	s = 0
	for i in range(0, r + 1, 2):
		s += ncr1(n, i) * ncr1(m, i)
		s %= mod
	return s

def poweroftwo(n):
	for i in range(40):
		if n < 2 ** i:
			return 2 ** i - 1

def prime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return n // i
	return 1
for i in range(int(input())):
	n = int(input())
	if n & n + 1 == 0:
		print(prime(n))
	else:
		print(poweroftwo(n))


import math

def check(n):
	lg = int(math.ceil(math.log2(n)))
	v = math.pow(2, lg) - 1
	return n == v
for q in range(int(input())):
	a = int(input())
	if check(a):
		ans = 1
		sp = 1000000000000
		i = 2
		while i * i <= a:
			while a % i == 0:
				sp = min(sp, i)
				ans *= i
				a //= i
			i += 1
		if a > 1:
			sp = min(sp, a)
			ans *= a
		ans //= sp
		print(ans)
	else:
		lg = len(bin(a)[2:])
		print(int(pow(2, lg)) - 1)


for _ in range(int(input())):
	a = int(input())
	b = bin(a)[2:]
	if '0' not in b:
		res = 1
		for b in range(2, int(a ** 0.5) + 2):
			if a % b == 0:
				res = max(res, b)
				res = max(res, a // b)
		print(res)
		continue
	i = len(b)
	print((1 << i) - 1)


ans = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
for i in range(int(input())):
	n = int(input())
	if n in ans:
		print(ans[n])
	else:
		x = 3
		while x <= n:
			x = 2 * x + 1
		print(x)


def intlog2(n):
	if n <= 0:
		return -1
	i = 0
	while 2 ** i <= n:
		i += 1
	return i - 1

def isfull(n):
	a = intlog2(n)
	if n == (1 << a + 1) - 1:
		return 1
	else:
		return 0

def calc(n):
	a = intlog2(n)
	if isfull(n):
		return [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401][a - 1]
	else:
		return (1 << a + 1) - 1
q = int(input())
for _ in range(q):
	a = int(input())
	print(calc(a))


from collections import defaultdict
import math

def ncr(n, m):
	return math.factorial(n) // (math.factorial(m) * math.factorial(n - m))

def gcd(n, m):
	return math.gcd(n, m)

def calculate(X, number_of_bits):
	number_of_bits = 8
	return (1 << number_of_bits) - 1 ^ X
power = []

def cal():
	temp = 1
	power.append(temp)
	for i in range(2, 30):
		temp *= 2
		power.append(temp)
cal()
t = int(input())
for t1 in range(0, t):
	n = int(input())
	ans = 1
	x = 1
	for i in range(0, len(power)):
		if power[i] <= n:
			ans = power[i]
			x = i + 1
		else:
			break
	if pow(2, x) - 1 == n:
		i = 2
		mx = 1
		while i < int(math.sqrt(n)) + 1:
			if n % i == 0:
				mx = max(mx, i, n // i)
			i += 1
		print(mx)
	else:
		print(pow(2, x) - 1)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = bin(n)[2:]
	e = '1' * len(s)
	if s.count('1') == len(s):
		i = 2
		f = 0
		while i < int(n ** 0.5) + 1:
			if n % i == 0:
				sys.stdout.write(str(n // i) + '\n')
				f = 1
				break
			i += 1
		if f:
			continue
		print(1)
	else:
		sys.stdout.write(str(int(e, 2)) + '\n')


import math

def result(a):
	n = 0
	while a != 0:
		n += 1
		a = a // 2
	return 2 ** n - 1

def brute(a):
	max_gcd = 1
	for i in range(2, int(math.sqrt(a)) + 1):
		if a % i == 0:
			return a // i
	return max_gcd

def main():
	q = int(input())
	for _ in range(q):
		a = int(input())
		if a & a + 1 != 0:
			sol = result(a)
			print(sol)
		else:
			sol = brute(a)
			print(sol)
main()


import math

def f(p):
	L = []
	for i in range(1, int(math.sqrt(p)) + 1):
		if p % i == 0:
			L.append(i)
			if i != p // i:
				L.append(p // i)
	L.sort()
	return L[-2]
R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	s = bin(n)[2:]
	l = len(s)
	p = s.count('1')
	if p == l:
		print(f(n))
	else:
		print(2 ** l - 1)


import math
q = int(input())
a = []
for i in range(q):
	a.append(int(input()))

def cal_maxgcd(x):
	bin_x = bin(x)[2:]
	bin_len = len(bin_x)
	max0 = 2 ** bin_len
	if x == max0 - 1:
		for m in range(2, int(math.sqrt(x)) + 1):
			if x % m == 0:
				return int(x / m)
		return 1
	return max0 - 1
for a0 in a:
	print(cal_maxgcd(a0))


def answer(n):
	if n == 1:
		return 1
	lmb = 0
	for i in range(26, -1, -1):
		if 1 << i & n:
			lmb = i
			break
	if n == 2 ** (lmb + 1) - 1:
		maxi = 1
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				maxi = max(maxi, n // i, i)
		return maxi
	return 2 ** (lmb + 1) - 1
t = int(input())
for i in range(t):
	n = int(input())
	print(answer(n))


t = int(input())
from math import log
import sys
for i in range(t):
	n = int(input())
	if log(n, 2) == int(log(n, 2)):
		print(2 * n - 1)
	elif log(n + 1, 2) == int(log(n + 1, 2)):
		a = 0
		for j in range(3, int(n ** 0.5) + 1):
			if n % j == 0:
				print(n // j)
				a = 1
				break
		if a == 0:
			print(1)
	else:
		b = bin(n).lstrip('0b')
		s = ''
		for j in b:
			if j == '0':
				s = s + '1'
			else:
				s = s + '0'
		a = int(s, 2)
		print(a ^ n)


def find_log(number):
	counter = 1
	while number > 1:
		number = number // 2
		counter += 1
	return counter

def __starting_point():
	q = int(input())
	a = [0 for i in range(q)]
	for i in range(q):
		a[i] = int(input())
	NUMS = [0 for i in range(24)]
	for i in range(24):
		NUMS[i] = 2 ** (i + 2) - 1
	PRIMES = [3, 7, 3, 31, 3, 127, 3, 7, 3, 23, 3, 8191, 3, 7, 3, 131071, 3, 524287, 3, 7, 3, 47, 3, 31]
	for i in range(q):
		if a[i] not in NUMS:
			k = find_log(a[i])
			print(2 ** k - 1)
		else:
			index = -1
			found = False
			while not found:
				index += 1
				if NUMS[index] == a[i]:
					found = True
			print(int(a[i] / PRIMES[index]))
__starting_point()


from math import log, sqrt
n = int(input())
for i in range(n):
	x = int(input())
	y = int(log(x, 2)) + 1
	if x == 2 ** y - 1:
		m = 1
		for i in range(2, int(sqrt(x)) + 1):
			if x % i == 0:
				m = max(m, x // i)
	else:
		m = 2 ** y - 1
	print(m)


import sys, math
ls2 = []
m = 1
for p in range(26):
	ls2.append(m)
	m += m
q = int(sys.stdin.readline())
for i in range(q):
	a = int(sys.stdin.readline())
	if a + 1 in ls2:
		cr = 1
		ms = int(math.sqrt(a))
		for se in range(3, ms + 1):
			if a % se == 0:
				cr = max(cr, a // se)
		print(cr)
	else:
		for st in ls2:
			if st > a:
				print(st - 1)
				break


from math import gcd

def ans(n):
	if n & n + 1 == 0:
		i = 2
		l = []
		while i * i <= n:
			if n % i == 0:
				l.append(i)
				if i * i != n:
					l.append(n // i)
			i += 1
		l.append(1)
		return max(l)
	else:
		bits = 0
		while n > 0:
			bits += 1
			n >>= 1
		return (1 << bits) - 1
for _ in range(int(input())):
	n = int(input())
	print(ans(n))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
from math import sqrt
nb_test = read_int()
for _ in range(nb_test):
	curr = int(input())
	curr_bin = format(curr, 'b')
	if curr_bin.count('0') == 0:
		for i in range(2, int(sqrt(curr)) + 1):
			if curr % i == 0:
				print(curr // i)
				break
		else:
			print(1)
	else:
		print(pow(2, len(curr_bin)) - 1)


from math import gcd, sqrt

def divisorGenerator(n):
	large_divisors = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			yield i
			if i * i != n:
				large_divisors.append(n // i)
	for divisor in reversed(large_divisors):
		yield divisor
n = int(input())
for i in range(n):
	c = int(input())
	u = len(bin(c + 1)) - 3
	if c + 1 == 2 ** u:
		if u % 2:
			print(list(divisorGenerator(c))[-2])
		else:
			print(c // 3)
	else:
		print(2 ** (u + 1) - 1)


import sys
import math
input = sys.stdin.readline

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
q = int(input())
l = []
for i in range(1, 28):
	l.append(smallestDivisor(2 ** i - 1))
for i in range(q):
	n = int(input())
	nbin = '{0:b}'.format(n)
	flag = False
	for j in range(len(nbin)):
		if nbin[j] != '1':
			flag = True
	if flag:
		print(2 ** len(nbin) - 1)
	else:
		print(n // l[len(nbin) - 1])


import sys
import math

def getAndParseInt(num=1):
	string = sys.stdin.readline().strip()
	if num == 1:
		return int(string)
	else:
		return [int(part) for part in string.split()]

def getAndParseString(num=1, delim=' '):
	string = sys.stdin.readline().strip()
	if num == 1:
		return string
	else:
		return [part for part in string.split(delim)]
q = getAndParseInt()
for i in range(q):
	a = getAndParseInt()
	notFull = False
	largest_power = 0
	cur_power = 0
	temp = a
	while temp > 0:
		if temp % 2 == 0:
			notFull = True
		else:
			largest_power = cur_power
		temp = temp // 2
		cur_power += 1
	if notFull:
		print((1 << largest_power + 1) - 1)
	else:
		max_fac = int(math.sqrt(a))
		div = 2
		isComp = False
		while div <= max_fac:
			if a % div == 0:
				isComp = True
				break
			div += 1
		if isComp:
			print(a // div)
		else:
			print(a // a)


import math
n = int(input())
for i in range(n):
	w = int(input())
	s = bin(w)[2:]
	if s.count('0') != 0:
		s = s.replace('0', '1')
		print(int(s, 2))
	else:
		for e in range(2, int(math.sqrt(w)) + 1):
			if w % e == 0:
				print(w // e)
				break
		else:
			print(1)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	ans = ''
	for _ in range(ii()):
		n = ii()
		b = bin(n)[2:]
		tmp = ''
		if n == 3:
			ans += '1\n'
		elif b.count('0') == 0:
			b = 1
			for d in range(2, int(n ** 0.5) + 1):
				if n % d == 0:
					b = max(b, n // d)
			ans += str(min(b, n ^ b)) + '\n'
		else:
			for i in range(len(b)):
				if b[i] == '1':
					tmp += '0'
				else:
					tmp += '1'
			tmp = int(tmp, 2)
			ans += str(n ^ tmp) + '\n'
	print(ans)
main()


for tc in range(int(input())):
	n = int(input())
	h = format(n, 'b')
	if set(h) == {'1'}:
		k = 1
		for i in range(2, int(n ** 0.5) + 1):
			if not n % i:
				k = i
				break
		print(n // k) if k != 1 else print(1)
	else:
		print(2 ** len(h) - 1)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import Counter, List
sys.setrecursionlimit(99999)
s = [1]
for i in range(60):
	s.append(s[-1] * 2 + 1)
for _ in range(int(input())):
	a = int(input())
	c = s[bisect.bisect_left(s, a)]
	if c == a:
		for i in range(2, int(a ** 0.5) + 1):
			if a % i == 0:
				print(a // i)
				break
		else:
			print(1)
	else:
		print(c)


ans = dict()
aa = '1\n1\n5\n1\n21\n1\n85\n73\n341\n89\n1365\n1\n5461\n4681\n21845\n1\n87381\n1\n349525\n299593\n1398101\n178481\n5592405\n1082401'
for (i, j) in zip(range(2, 26), aa.split('\n')):
	ans[2 ** i - 1] = j
q = int(input())
a = [int(input()) for _ in range(q)]
from math import log2, ceil
for i in a:
	if int(log2(i + 1)) != log2(i + 1):
		print(2 ** ceil(log2(i + 1)) - 1)
	else:
		print(ans[i])


from math import log2, sqrt
n = int(input())
for i in range(n):
	a = int(input())
	c = 2 ** (int(log2(a)) + 1) - 1
	if a != c:
		print(c)
	else:
		for i in range(3, int(sqrt(a)) + 1, 2):
			if a % i == 0:
				print(a // i)
				break
		else:
			print(1)


from math import ceil, log2, gcd
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = int(log2(n)) + 1
	val = 2 ** l - 1
	if val == n:
		i = 2
		while i * i < n:
			if n % i == 0:
				break
			i += 1
		print(1 if i * i > n else n // i)
	else:
		print(val)


import math

def find_largest_non_trivial_divisor(n):
	bound = min(math.ceil(math.sqrt(n) + 2) + 1, n)
	for d in range(2, bound):
		if n % d == 0:
			return d
	return n
num_tests = int(input())
for _ in range(num_tests):
	n = int(input())
	larg_bit_pos = 0
	x = n
	while x > 1:
		x //= 2
		larg_bit_pos += 1
	best0 = 2 ** (larg_bit_pos + 1) - 1
	if n != best0:
		print(best0)
	else:
		d = find_largest_non_trivial_divisor(n)
		print(n // d)


def read_int():
	return int(input().strip())

def read_string():
	return input().strip()

def read_int_list():
	return list(map(int, input().strip().split()))

def read_string_list():
	return input().strip().split()
import sys, math
q = read_int()
pows = set()
for i in range(1, 26):
	pows.add(2 ** i - 1)
for i in range(q):
	n = read_int()
	if n in pows:
		out = 1
		for i in range(math.ceil(math.sqrt(n)), 1, -1):
			if n % i == 0:
				out = n // i
		print(out)
	else:
		print(2 ** (int(math.log2(n)) + 1) - 1)


for _ in range(int(input())):
	n = int(input())
	if n & n + 1:
		print(2 ** (len(bin(n)) - 2) - 1)
	else:
		x = 1
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				x = n // i
				break
		print(x)


import math

def divisorGenerator(n):
	large_divisors = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			yield i
			if i * i != n:
				large_divisors.append(n // i)
	for divisor in reversed(large_divisors):
		yield divisor
n = int(input())
s = [1]
for i in range(1, 25):
	s.append(s[-1] + 2 ** i)
for _ in range(n):
	x = int(input())
	if x in s:
		print(max(set(divisorGenerator(x)) - {x}))
	else:
		t = bin(x)[2:]
		t2 = []
		for i in t:
			if i == '1':
				t2.append('0')
			else:
				t2.append('1')
		y = int(''.join(t2), 2)
		print(x ^ y)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())

def check(a):
	for i in range(2, int(math.sqrt(a)) + 2):
		if a % i == 0:
			return a // i
	return 1
q = int(input())
for _ in range(q):
	a = int(input())
	temp = a + 1
	b = 0
	while temp % 2 == 0:
		temp = temp // 2
		b += 1
	if temp == 1:
		print(check(a))
	else:
		temp = 1
		for i in range(35):
			if temp > a:
				print(temp - 1)
				break
			temp = temp * 2


q = int(input())
da = {1: 0, 3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
for i in range(q):
	qq = int(input())
	if qq in da:
		print(da[qq])
		continue
	for j in range(26):
		if 2 ** j > qq:
			print(2 ** j - 1)
			break


from math import log2
from math import sqrt
q = int(input())
for i in range(q):
	a = int(input())
	if log2(a + 1) * 10 % 10 == 0:
		for j in range(2, int(sqrt(a)) + 1):
			if a % j == 0:
				print(a // j)
				break
		else:
			print(1)
	else:
		print(2 ** (int(log2(a)) + 1) - 1)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def stupid(x):
	r = 1
	for i in range(1, x):
		r = max(r, gcd(i & x, i ^ x))
	return r
d = dict()
d[511] = 73
d[2047] = 89
d[32767] = 4681
d[2097151] = 299593
d[8388607] = 178481
d[33554431] = 1082401

def smart(x):
	if x in d:
		return d[x]
	if x & x + 1 == 0:
		i = 0
		while (1 << i) - 1 != x:
			i += 1
		if i % 2 == 0:
			z = 0
			for i in range(0, i, 2):
				z += 1 << i
			return z
		else:
			return 1
	else:
		i = 1
		z = 0
		while i < x:
			if i & x == 0:
				z += i
			i *= 2
		return x + z
q = mint()
for i in range(q):
	x = mint()
	print(smart(x))


import sys
from math import gcd, log2

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip('\n')
out = [-1, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
l = [(1 << i) - 1 for i in range(26)]
for _ in range(int(input())):
	n = int(input())
	if n in l:
		c = 0
		for i in l:
			if i == n:
				print(out[c - 1])
				break
			c += 1
	else:
		k = int(log2(n)) + 1
		print((1 << k) - 1)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
d = {1: 0, 3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
for _ in range(ii()):
	n = ii()
	if n in d:
		ans = d[n]
	else:
		ans = 2 ** n.bit_length() - 1
	print(ans)


import sys
input = sys.stdin.readline
q = int(input())
x = []
for i in range(q):
	v = int(input())
	tv = v
	(cnt, len) = (0, 0)
	while tv > 0:
		if tv & 1:
			cnt += 1
		len += 1
		tv //= 2
	if cnt != len:
		print(2 ** len - 1)
	else:
		a = 1
		i = 2
		while i * i <= v:
			if v % i == 0:
				a = v // i
				break
			i += 1
		print(a)


q = int(input())
for i in range(q):
	n = int(input())
	x = 1
	while x <= n:
		x *= 2
	if n < x - 1:
		print(x - 1)
	else:
		ans = 1
		i = 2
		while i ** 2 <= n:
			if n % i == 0:
				ans = n // i
				break
			i += 1
		print(ans)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def printDivisors(n):
	A = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				A.append(i)
			else:
				A.append(i)
				A.append(n // i)
		i = i + 1
	return A

def solve():
	A = []
	j = 1
	for i in range(28):
		j *= 2
		A.append(j - 1)
	for _ in range(int(input())):
		(n,) = aj()
		if not n in A:
			print(A[bisect.bisect_left(A, n)])
		else:
			d = printDivisors(n)
			d.sort()
			d.pop()
			x = n & d[-1]
			y = n ^ d[-1]
			print(math.gcd(x, y))
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import math
q = int(input())
lista = []
for i in range(0, int(q)):
	lista.append(int(input()))
for i in range(0, q):
	a = lista[i]
	if a == 1:
		print(-1)
	else:
		bin_a = ''
		temp = a
		max_1 = True
		while temp != 0:
			x = temp % 2
			if x == 0:
				max_1 = False
			bin_a = str(x) + bin_a
			temp //= 2
		if max_1:
			div = 3
			result = 0
			while div <= math.sqrt(a):
				if a % div == 0:
					result = a // div
					break
				div += 1
			if result == 0:
				print(1)
			else:
				print(result)
		else:
			b = 2 ** len(bin_a) - 1
			print(b)


from operator import xor
import math
q = int(input())

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def guess_d(x):
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			return x // i
	return 1
for _ in range(q):
	a = int(input())
	correct = 0
	guess_b = 0
	pow = 1
	tmp = a
	while tmp:
		guess_b += (tmp % 2 + 1) % 2 * pow
		pow *= 2
		tmp = tmp // 2
	if guess_b == 0:
		guess_b = guess_d(a)
	guess = computeGCD(xor(guess_b, a), guess_b & a)
	print(guess)


import math

def onesComplement(n):
	number_of_bits = int(math.floor(math.log(n) / math.log(2))) + 1
	return (1 << number_of_bits) - 1 ^ n
d = {1: 0, 3: 1, 7: 1, 16777215: 5592405, 8191: 1, 4194303: 1398101, 2097151: 299593, 65535: 21845, 16383: 5461, 262143: 87381, 33554431: 1082401, 15: 5, 524287: 1, 31: 1, 8388607: 178481, 32767: 4681, 1023: 341, 2047: 89, 63: 21, 127: 1, 255: 85, 1048575: 349525, 511: 73, 67108863: 22369621, 4095: 1365, 131071: 1}
q = int(input())
while q:
	q -= 1
	flag = False
	n = int(input())
	for i in range(1, 26):
		a = 2 ** i
		if n == a - 1:
			b = n
			print(d[n])
			flag = True
			break
		if n < a:
			break
	if flag:
		continue
	b = onesComplement(n)
	a = n
	print(math.gcd(a ^ b, a & b))


for _ in range(int(input())):
	x = int(input())
	b = bin(x)[2:]
	if set(b) == {'1'}:
		k = 1
		for i in range(2, int(x ** 0.5) + 1):
			if not x % i:
				k = i
				break
		print((x // k, 1)[k == 1])
	else:
		print(2 ** len(b) - 1)


import math

def func(x):
	res = '0'
	c = bin(x)
	b = c[2:]
	n = len(b)
	st = False
	if '0' in b:
		return int('1' * n, 2)
	else:
		n = int(c, 2)
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				return n // i
		return 1
q = int(input())
for i in range(q):
	print(func(int(input())))


q = int(input())
for i in range(q):
	a = int(input())
	c = (1 << len(bin(a)) - 2) - 1
	b = c ^ a
	if c != a:
		print(c)
		continue
	i = 2
	ans = 1
	while i * i <= a:
		if a % i == 0:
			ans = max(ans, i, a // i)
		i += 1
	print(ans)


from math import sqrt
q = int(input())
for _ in range(q):
	a = int(input())
	bi = format(a, 'b')
	if bi.count('0') == 0:
		for i in range(2, int(sqrt(a)) + 1):
			if a % i == 0:
				print(a // i)
				break
		else:
			print(1)
	else:
		print(pow(2, len(bi)) - 1)


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))

def is_power(n):
	n = n / 2
	if n == 2:
		return True
	elif n > 2:
		return is_power(n)
	else:
		return False
q = nn()
for i in range(q):
	a = nn()
	if is_power(a + 1):
		m = 0
		p = 0
		while 2 ** p < a:
			p += 1
		d = 0
		c = 3
		while c * c <= a:
			if a % c == 0:
				d = c
				break
			c += 1
		if d == 0:
			print(1)
		else:
			print(a // d)
	else:
		p = 0
		while 2 ** p <= a:
			p += 1
		print(2 ** p - 1)


from functools import lru_cache

@lru_cache(maxsize=None)
def f(a):
	n = a.bit_length()
	axb = (1 << n) - 1
	if axb != a:
		ans = axb
	else:
		ans = 1
		b = 1
		while b ** 2 <= a:
			if a % b == 0:
				if (a - b) % b == 0:
					ans = max(ans, b)
				bb = a // b
				if bb != a:
					if (a - bb) % bb == 0:
						ans = max(ans, bb)
			b += 2
	return ans
q = int(input())
for _ in range(q):
	a = int(input())
	print(f(a))


import math

def prost(n):
	i = 2
	while i <= n ** 0.5:
		if n % i == 0:
			return n // i
		i += 1
	return 1
q = int(input())
for i in range(q):
	b = int(input())
	lena = int(math.log(b, 2)) + 1
	if b & b + 1 == 0:
		print(prost(b))
	else:
		print(2 ** lena - 1)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(q,) = I()
while q:
	q -= 1
	(n,) = I()
	ans = 0
	for i in range(26, -1, -1):
		if n >> i & 1:
			for bit in range(i - 1, -1, -1):
				if n >> bit & 1:
					continue
				ans ^= 1 << bit
			break
	res = gcd(ans ^ n, ans & n)
	if ans == 0:
		res = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i:
				continue
			if gcd(n - i, i) == i:
				res = max(res, i)
			x = n // i
			if x == n:
				continue
			if gcd(n - x, x) == x:
				res = max(res, x)
	print(res)


import math
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	m = n
	ans = 2
	while n > 1:
		n = n // 2
		ans *= 2
	ans -= 1
	k = 1
	if ans == m:
		a1 = math.sqrt(ans)
		a = int(a1)
		for i in range(2, a + 1):
			if ans % i == 0:
				k = i
				break
		if k == 1:
			k = ans
	ans = ans // k
	print(ans)


from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
setrecursionlimit(10 ** 7)

def read():
	return int(input())

def reads():
	return [int(x) for x in input().split()]

def largest_factor(x):
	ans = 1
	for y in range(2, 2 ** 13):
		if x % y == 0:
			ans = max(ans, x // y)
	return ans

def solve(a):
	highest_bit = max((1 << i for i in range(30) if 1 << i & a > 0))
	M = highest_bit * 2 - 1
	return M if a != M else largest_factor(M)
q = read()
for _ in range(q):
	a = read()
	print(solve(a))


from math import sqrt, ceil

def largest_divisor(a):
	for i in range(2, ceil(sqrt(a))):
		if a % i == 0:
			return a // i
	else:
		return 1
T = int(input())
for i in range(T):
	a = int(input())
	b = bin(a)[2:]
	for i in b:
		if i == '0':
			s = ''
			for i in range(len(b)):
				s += '1'
			s = int(s, 2)
			ans = s
			break
	else:
		ans = largest_divisor(a)
	print(ans)


import sys
from math import log, sqrt
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	x = int(input())
	y = int(log(x, 2)) + 1
	if x == 2 ** y - 1:
		m = 1
		for i in range(2, int(sqrt(x)) + 1):
			if x % i == 0:
				m = max(m, x // i)
	else:
		m = 2 ** y - 1
	print(m)


import math
from sys import stdin
q = int(input())
l = stdin.read().splitlines()
for i in l:
	n = int(i)
	k = int(math.log2(n + 1))
	if 1 << k < n + 1:
		print((1 << k + 1) - 1)
		continue
	else:
		found = False
		for j in range(2, int(math.sqrt(n)) + 1):
			if n % j == 0:
				print(n // j)
				found = True
				break
		if not found:
			print(1)


import collections as cc
import sys
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	if n & n + 1:
		print(2 ** n.bit_length() - 1)
	else:
		temp = n
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				temp = i
				break
		print(n // temp)


from math import gcd, sqrt, ceil, log2

def is_power2(num):
	return num != 0 and num & num - 1 == 0
q = int(input())
for _ in range(q):
	n = int(input())
	if n < 3:
		if n == 0:
			print(0)
		if n == 1:
			print(0)
		if n == 2:
			print(3)
	elif is_power2(n + 1):
		got = False
		for i in range(2, ceil(sqrt(n))):
			if n % i == 0:
				print(n // i)
				got = True
				break
		if not got:
			print(1)
	else:
		print(2 ** ceil(log2(n + 1)) - 1)


q = int(input())

def racunaj():
	s = []
	for i in range(27):
		d = 2
		n = 2 ** i - 1
		z = 1
		while d * d <= n:
			if n % d == 0:
				z = n // d
				break
			d += 1
		s.append(z)
	return s
najdel = racunaj()
for _q in range(q):
	n = int(input())
	z = 1
	c = 1
	while z < n:
		z = 2 * z + 1
		c += 1
	if z > n:
		print(z)
	else:
		print(najdel[c])


import math
q = int(input())
for i in range(q):
	a = int(input())
	x = int(math.log(a, 2)) + 1
	if a + 1 != 2 ** x:
		print(2 ** x - 1)
	else:
		ans = 1
		for i in range(2, int(math.sqrt(a)) + 1):
			if a % i == 0:
				ans = max(ans, a / i)
		print(int(ans))


from math import log2
q = int(input())
l = []
for i in range(2, 26):
	l.append(2 ** i - 1)
b = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
for alskfklafj in range(q):
	x = int(input())
	if x in l:
		for i in range(len(l)):
			if l[i] == x:
				print(b[i])
				break
	else:
		print(2 ** (int(log2(x)) + 1) - 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def calc(n):
	m = n
	n = math.log(n + 1, 2)
	n = 2 ** math.ceil(n) - 1
	n -= m
	return n
for i in range(int(input())):
	n = int(input())
	w = calc(n)
	if w != 0:
		print(math.gcd(n ^ w, n & w))
	elif math.log(n + 1, 2) % 2 == 0:
		print(n // 3)
	else:
		f = 1
		for j in range(2, int(n ** 0.5) + 1):
			if n % j == 0:
				f = 0
				print(n // j)
				break
		if f == 1:
			print(1)


for _ in range(int(input())):
	a = int(input())
	pow2 = 1
	while pow2 <= a:
		pow2 <<= 1
	pow2 -= 1
	if a < pow2:
		print(pow2)
	else:
		d = 2
		ans = 1
		while d * d <= a:
			if a % d == 0:
				ans = a // d
				break
			d += 1
		print(ans)


import math

def findlarg(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return n // i
		i += 1
	return 1
q = int(input())
j = 0
a = []
while j < q:
	a.append(int(input()))
	j += 1
for i in range(q):
	if a[i] == 1:
		print(0)
	elif a[i] == 2:
		print(3)
	else:
		p = int(math.log2(a[i]))
		if 2 ** (p + 1) - 1 == a[i]:
			print(findlarg(a[i]))
		else:
			print(2 ** (p + 1) - 1)


l = [2 ** i - 1 for i in range(1, 26)]
d = {65535: 21845, 4095: 1365, 2047: 89, 1023: 341, 16777215: 5592405, 63: 21, 33554431: 1082401, 255: 85, 2097151: 299593, 15: 5, 4194303: 1398101, 8388607: 178481, 262143: 87381, 511: 73, 16383: 5461, 1048575: 349525, 32767: 4681}
for _ in range(int(input())):
	n = int(input())
	flag = False
	if n not in d.keys():
		for i in l:
			if n == i:
				flag = True
				break
			elif n < i:
				break
		if flag:
			print(1)
		else:
			print(i)
	else:
		print(d[n])


q = int(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def largest(n):
	for i in range(2, n):
		if n % i == 0:
			return n // i
		if i * i > n:
			break
	return 1
for i in range(q):
	n = int(input())
	a = decimalToBinary(n)
	A = [ch for ch in a]
	if '0' in A:
		x = ['1'] * len(A)
		y = ''.join(x)
		print(int(y, 2))
	else:
		print(largest(n))


f"{(lambda math, itertools: [(lambda N: print((1 << int(math.log2(N) + 1e-12 + 1)) - 1) if N & N + 1 else (lambda w: [list(itertools.takewhile(lambda i: N % i or [print(N // i), w.__setitem__(0, 0)][1], (i for i in range(2, int(math.sqrt(N)) + 1)))), w[0] and print(1)])([1]))(int(input())) for t in range(int(input()))])(__import__('math'), __import__('itertools'))}"


for _ in range(int(input())):
	a = int(input())
	if bin(a)[2:].count('0') == 0:
		ret = 0
		for i in range(2, int(a ** 0.5) + 1):
			if a % i == 0:
				print(a // i)
				break
		else:
			print(1)
	else:
		p = 0
		while a > 0:
			a >>= 1
			p += 1
		print((1 << p) - 1)


import math

def lf(n):
	for i in range(3, math.floor(math.sqrt(n)) + 1):
		if n % i == 0:
			return n // i

def fun(a):
	j = math.log(a + 1) / math.log(2)
	if j == math.floor(j):
		if j in [2, 3, 5, 7, 13, 17, 19]:
			return 1
		elif j == 11:
			return 89
		elif j == 23:
			return 178481
		else:
			return lf(a)
	else:
		j = math.floor(j)
		return 2 ** (j + 1) - 1
q = int(input())
for i in range(q):
	a = int(input())
	print(fun(a))


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	return ' '.join(list(map(str, a)))

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)
m = [1, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
n = ini()
for _ in range(n):
	a = ini()
	x = 0
	x1 = ceil(log2(a))
	x2 = floor(log2(a))
	if x2 == x1:
		x = x1 + 1
	else:
		x = x1
	b = int(pow(2, x)) - 1
	if a != b:
		print(b)
	else:
		x = floor(log2(a))
		print(m[x])


import math
q = int(input())
for i in range(q):
	n = int(input())
	k = str(format(bin(n)))
	if k[3:].count('0') == 0:
		m = 0
		for j in range(2, int(math.sqrt(n)) + 1):
			if n % (j + 1) == 0:
				div = j
				m = 1
				break
		if m == 0:
			print(1)
		else:
			print(n // (div + 1))
	else:
		print(int('1' * (len(k) - 2), 2))


Q = int(input())
A = [int(input()) for i in range(Q)]
OTHER = {2 ** i - 1 for i in range(2, 26)}
OT = [2 ** i - 1 for i in range(1, 26)]
ANSDICT = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
for a in A:
	if a in OTHER:
		print(ANSDICT[a])
	else:
		for i in range(30):
			if a < OT[i]:
				print(OT[i])
				break


from math import gcd

def divisors(n):
	div = []
	p = n ** 0.5
	p = int(p) + 1
	for i in range(2, p):
		if n % i == 0:
			if n // i == i:
				div.append(i)
			else:
				div += [i, n // i]
	return div
for _ in range(int(input())):
	n = int(input())
	for i in range(1, 27):
		x = 2 ** i
		if x > n:
			p = i
			break
	x = 2 ** p
	x -= 1
	if n == x:
		div = divisors(n)
		div.sort()
		if len(div) == 0:
			print(1)
		else:
			print(max(div))
	else:
		print(x)


from io import BytesIO, IOBase
from math import sqrt
import sys, os
inpl = lambda : list(map(int, input().split()))
inpm = lambda : map(int, input().split())
inpi = lambda : int(input())
inp = lambda : input()
(rev, ra, l) = (reversed, range, len)
P = print
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def B(n):
	return bin(n).replace('0b', '')

def factors(n):
	arr = []
	for i in ra(2, int(sqrt(n)) + 1):
		if n % i == 0:
			arr.append(i)
			if i * i != n:
				arr.append(int(n / i))
	return arr
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys, operator, math, operator
from collections import Counter
import random
tc = inpi()
while tc:
	tc -= 1
	n = inpi()
	b = B(n)
	sets = b.count('1')
	if sets == len(b):
		fac = factors(n)
		if len(fac) == 0:
			P(1)
		else:
			fac.sort()
			P(fac[-1])
	else:
		no = '1' * len(b)
		ans = int(no, 2)
		P(ans)


import math
q = int(input())
for i in range(q):
	a = int(input())
	deli = 0
	b = a
	ch = 2
	s = ''
	c = 2 ** math.ceil(math.log2(a + 1)) - 1
	if a == 1:
		print(1)
	elif a == c:
		while ch <= b ** (1 / 2) and deli == 0:
			if b % ch == 0:
				deli = b // ch
			ch += 1
		if deli == 0:
			print(1)
		else:
			print(deli)
	else:
		print(c)


from collections import deque
import pdb
import heapq
from heapq import *
from pprint import pprint
from bisect import *
mod = 99999999999

def rI():
	return [int(i) for i in input().split()]

def gdc(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b

def ggg(zz):
	mm = 0
	for j in range(1, zz):
		if mm < gdc(zz ^ j, zz & j):
			mm = gdc(zz ^ j, zz & j)
			mmp = j
	return mm
dicc = {1: 0, 3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
q = rI()[0]
for i in range(q):
	n = rI()[0]
	if n in dicc:
		print(dicc[n])
		continue
	de = n
	n = bin(n)[2:]
	ans = 0
	for j in n:
		if j == '0':
			ans = ans << 1
			ans += 1
		else:
			ans = ans << 1
	if ans == 0:
		if len(n) % 2 == 1:
			print(1)
			continue
		else:
			knt = len(n)
			kk = 0
			f = False
			ans = 0
			while kk != knt:
				kk += 1
				if f is False:
					ans = ans << 1
					ans += 1
					f = True
				else:
					ans = ans << 1
					f = False
	print(gdc(de ^ ans, de & ans))


import math
q = int(input())
for i in range(q):
	n = int(input())
	z = n
	d = ''
	while z != 0:
		d = d + str(z % 2)
		z = z // 2
	d = d[::-1]
	if len(d) == d.count('1'):
		for e in range(2, int(math.sqrt(n)) + 1):
			if n % e == 0:
				print(n // e)
				break
		else:
			print(1)
	else:
		print(2 ** len(d) - 1)


from math import sqrt
q = int(input())
for i in range(q):
	x = int(input())
	y = bin(x)[2:]
	z = 2 ** len(y) - 1
	if z != x:
		b = z & x
		print(z)
	else:
		ans = 1
		for i in range(2, int(sqrt(z)) + 1):
			if z % i == 0:
				ans = max(ans, i, z // i)
		print(ans)


def ispow2(x):
	if x & x - 1 == 0:
		return 1
	return 0
t = int(input())
for you in range(t):
	n = int(input())
	if ispow2(n + 1) == 0:
		for j in range(25, -1, -1):
			if n & 1 << j:
				ans = j
				break
		print((1 << ans + 1) - 1)
	else:
		maxa = 1
		i = 2
		while i * i <= n:
			if n % i == 0:
				maxa = max(maxa, n // i)
				break
			i += 1
		print(maxa)


import math
q = int(input())
for k in range(q):
	a = int(input())
	c = list(bin(a))
	c = c[2:]
	d = c.copy()
	z = '0'
	ans = []
	if a == 8388607:
		print('178481')
	elif a == 2047:
		print('89')
	elif a == 1:
		print(a)
	elif z in d:
		for i in range(len(d)):
			if c[i] == '0':
				d[i] = '1'
			else:
				d[i] = '0'
		b = int(''.join(d), 2)
		t1 = a ^ b
		t2 = a & b
		print(math.gcd(t1, t2))
	else:
		ans = []
		l = len(d)
		for i in range(1, l, 1):
			j = l - 1
			count = 0
			while count < l:
				d[j] = '1'
				j = j - 1
				count += 1
				if count == l:
					break
				for m in range(0, i, 1):
					d[j - m] = '0'
					count += 1
					if count == l:
						break
				j = j - m - 1
			b = int(''.join(d), 2)
			t1 = a ^ b
			t2 = a & b
			ans.append(math.gcd(t1, t2))
		print(max(ans))


q = int(input())
for i in range(q):
	a = int(input())
	ans = 1
	while ans <= a:
		ans *= 2
	if a < ans - 1:
		print(ans - 1)
	else:
		ans = 1
		d = 2
		while d * d <= a:
			if a % d == 0:
				ans = a // d
				break
			d += 1
		print(ans)


from math import gcd, log2
q = int(input())
beki = [2 ** i - 1 for i in range(26)]
kai = [0, 1, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, (pow(2, 14) - 1) // 3, (pow(2, 15) - 1) // 7, (pow(2, 16) - 1) // 3, 1, (pow(2, 18) - 1) // 3, 1, (pow(2, 20) - 1) // 3, (pow(2, 21) - 1) // 7, (pow(2, 22) - 1) // 3, 178481, (pow(2, 24) - 1) // 3, (pow(2, 25) - 1) // 31]
for i in range(q):
	a = int(input())
	if a in beki:
		print(kai[int(log2(a + 1))])
	else:
		print(pow(2, int(log2(a) + 1)) - 1)


import math
n = int(input())

def power(q):
	x = 1
	while x <= q:
		x = x * 2
	return x

def divisor(p):
	for i in range(2, int(math.sqrt(p)) + 1):
		if p % i == 0:
			return p // i
	return 1
for i in range(n):
	a = int(input())
	b = power(a)
	if a != b - 1:
		print(b - 1)
	else:
		print(divisor(a))


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5:
	from math import gcd
else:
	from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(a, b=1):
	return int(-(-a // b))

def round(x):
	return int((x * 2 + 1) // 2)

def fermat(x, y, MOD):
	return x * pow(y, MOD - 2, MOD) % MOD

def lcm(x, y):
	return x * y // gcd(x, y)

def lcm_list(nums):
	return reduce(lcm, nums, 1)

def gcd_list(nums):
	return reduce(gcd, nums, nums[0])

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
Q = INT()
for i in range(Q):
	a = INT()
	bin_a = format(a, 'b')
	if '0' in bin_a:
		bin_a = bin_a.replace('0', '1')
		print(int(bin_a, 2))
	else:
		for i in range(2, int(sqrt(a)) + 2):
			if a % i == 0:
				print(a // i)
				break
		else:
			print(1)


import math
q = int(input())
for _ in range(q):
	n = int(input())
	i = 0
	while 2 ** i <= n:
		i += 1
	if n == 2 ** i - 1:
		for j in range(2, max(2, int(math.sqrt(n)) + 1)):
			if n % j == 0:
				print(n // j)
				break
		else:
			print(1)
	else:
		print(2 ** i - 1)


import math

def is_prime(n):
	if n == 2 or n == 3:
		return True
	if n < 2 or n % 2 == 0:
		return False
	if n < 9:
		return True
	if n % 3 == 0:
		return False
	r = int(n ** 0.5)
	f = 5
	while f <= r:
		if n % f == 0:
			return False
		if n % (f + 2) == 0:
			return False
		f += 6
	return True
t = int(input())
while t > 0:
	a = int(input())
	s = str(bin(a))
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
	if c == math.floor(math.log(a, 2)) + 1:
		if is_prime(a):
			print(1)
		else:
			for i in range(2, math.ceil(math.sqrt(a)) + 1):
				if a % i == 0:
					break
			print(a // i)
	else:
		print(pow(2, math.floor(math.log(a, 2)) + 1) - 1)
	t -= 1


from functools import lru_cache

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
prec = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}

@lru_cache()
def solve(k):
	s = bin(k)[2:]
	if not s.count('0'):
		return prec[k]
	else:
		return 2 ** len(s) - 1
n = int(input())
for i in range(n):
	k = int(input())
	print(solve(k))


import math
l = [1, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
q = int(input())
for _ in range(q):
	b = int(input())
	if int(math.log2(b)) < int(math.log2(b + 1)):
		print(l[int(math.log2(b))])
	else:
		dig = int(math.log2(b)) + 1
		print(2 ** dig - 1)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def maximumXOR(n, l, r):
	x = 0
	for i in range(int(math.log2(r)), -1, -1):
		if n & 1 << i:
			if x > r or x + (1 << i) - 1 < l:
				x ^= 1 << i
		elif x ^ 1 << i <= r:
			x ^= 1 << i
	return n ^ x

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
li = []
for i in range(2, 26):
	temp = '1' * i
	temp = int(temp, 2)
	li.append(temp)
q = intIn()
while q > 0:
	q -= 1
	a = intIn()
	ans = {}
	if a in li:
		ele = smallestDivisor(a)
		print(a // ele)
	else:
		print(maximumXOR(a, 1, a - 1))


t = int(input())
for _ in range(t):
	n = int(input())
	b = bin(n)
	b = b[2:]
	p = 1
	if '0' in b:
		print(2 ** len(b) - 1)
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				p = n // i
				p = max(p, i)
				break
		print(p)


import math
q = int(input(''))
for _ in range(q):
	n = int(input(''))
	ans = -1
	if n & n + 1 == 0:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				ans = n // i
				break
		if ans == -1:
			ans = 1
		print(ans)
		continue
	x = bin(n)
	x = x[2:]
	print(2 ** len(x) - 1)


import math
q = int(input())
while q > 0:
	val = int(input())
	res = 0
	while 1 << res <= val:
		res += 1
	ans = (1 << res) - 1
	maxm = 1
	if ans != val:
		print(ans)
	else:
		for i in range(2, int(math.sqrt(val)) + 1):
			if val % i == 0:
				maxm = max(maxm, int(val / i))
		print(maxm)
	q -= 1


import math
aaa = []
for i in range(1, 30):
	aaa.append(2 ** i - 1)

def printDivisors(n):
	list = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(i)
				list.append(int(n / i))
	list.sort()
	return list[-2]

def f(n):
	if n in aaa:
		return printDivisors(n)
	else:
		j = 0
		for i in range(29):
			if aaa[i] > n:
				j = i
				break
		return aaa[j]
for i in range(int(input())):
	print(f(int(input())))


from math import floor

def func(x):
	bo = True
	store = 1
	count = 0
	while store <= x:
		if x & store == 0:
			bo = False
		count += 1
		store *= 2
	if bo == False:
		return store - 1
	else:
		for y in range(2, floor(x ** 0.5) + 1):
			if x % y == 0:
				return x // y
		return 1

def main():
	count = int(input())
	for _ in range(count):
		print(func(int(input())))
main()


import math

def main():
	num_dict = {2: 3, 3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
	q = int(input())
	for _ in range(q):
		a = int(input())
		if a in num_dict:
			print(num_dict[a])
		else:
			temp = int(math.log(a, 2))
			print(pow(2, temp + 1) - 1)

def __starting_point():
	main()
__starting_point()


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(n ** 0.5) + 1):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def power(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a
		b = b >> 1
		a = a * a
	return res

def op(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return n // i
	return 1
ans = {}
for i in range(1, 26):
	xx = power(2, i) - 1
	if isPrime(xx):
		ans[xx] = 1
	else:
		an = 1
		an = max(an, op(xx))
		anss = 1
		anss = max(anss, gcd(xx ^ an, xx & an))
		ans[xx] = anss
n = int(input())
for rr in range(n):
	a = int(input())
	if a & a + 1 == 0:
		print(ans[a])
	else:
		y = bin(a)
		y = y[2:]
		aa = ''
		for i in range(len(y)):
			if y[i] == '1':
				aa += '0'
			else:
				aa += '1'
		b = int(aa, 2)
		print(gcd(a ^ b, a & b))


for _ in range(int(input())):
	n = int(input())
	if n + 1 & n:
		print(2 ** n.bit_length() - 1)
	else:
		x = 2
		while n % x:
			if x * x > n:
				x = n
				break
			x += 1
		print(n // x)


from math import gcd
T = int(input())
ar = []
for i in range(1, 31):
	ar.append(2 ** i)
for _ in range(T):
	n = int(input())
	flag = False
	for i in ar:
		if n + 1 == i:
			flag = True
			break
	if flag:
		a = 1
		i = 2
		while i * i <= n:
			if n % i == 0:
				a = max(a, i)
			if n % (n // i) == 0:
				a = max(a, n // i)
			i += 1
		print(a)
	else:
		for i in ar:
			if i > n:
				break
		print(i - 1)


from math import gcd, sqrt, ceil

def check_pow2(a):
	return 2 ** a.bit_length() == a + 1

def max_div(a):
	for i in range(2, ceil(sqrt(a)) + 1):
		if a % i == 0:
			return max(i, a // i)
	return 1

def solve_dumb(a):
	mv = 0
	for b in range(1, a):
		v = gcd(a ^ b, a & b)
		if v > mv:
			mv = v
	return mv

def solve(a):
	if check_pow2(a):
		return max_div(a)
	else:
		return 2 ** a.bit_length() - 1
q = int(input())
for i in range(q):
	n = int(input())
	print(solve(n))


import math

def factors(num):
	ans = 1
	n = int(math.sqrt(num)) + 1
	for i in range(1, n):
		if num % i == 0:
			a1 = num // i
			a2 = i
			if a1 < num:
				if a1 > ans:
					ans = a1
			if a2 < num:
				if a2 > ans:
					ans = a2
	return ans
t = int(input())
for _ in range(t):
	a = int(input())
	s1 = len(str(bin(a))) - 2
	t1 = '0b' + '1' * s1
	temp = int(t1, 2) ^ a
	if temp != 0:
		print(temp ^ a)
	else:
		x = factors(a)
		print(x)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
p = []
for i in range(1, 26):
	p.append(2 ** i - 1)
for _ in range(l()[0]):
	a = l()[0]
	if a in p:
		ans = 1
		for i in range(2, int(a ** 0.5) + 1):
			if a % i == 0:
				ans = a // i
				break
		print(ans)
	else:
		y = br(p, a)
		print(p[y])


import math

def ans2(n):
	if n == 0:
		return 1
	res = 2 ** (math.floor(math.log2(n)) + 1) - 1
	if res == n:
		lst = [1, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
		res = lst[math.ceil(math.log2(n)) - 1]
	if n == 2:
		res = 3
	if n == 1:
		res = 1
	return res

def ans(n):
	maxg = 1
	g = 1
	for i in range(1, n):
		a = i ^ n
		b = i & n
		if math.gcd(a, b) > maxg:
			maxg = math.gcd(a, b)
			g = i
	return maxg
q = int(input())
for p in range(q):
	num = int(input())
	print(ans2(num))


import math
q = int(input())
for i in range(q):
	a = int(input())
	l = int(math.log2(a))
	if a + 1 != 2 ** (l + 1):
		print(2 ** (l + 1) - 1)
	else:
		j = 2
		while j * j <= a:
			if a % j == 0:
				ans = a // j
				break
			j += 1
		else:
			ans = 1
		print(ans)


def f(a):
	digit = 0
	tmp = a
	while tmp > 0:
		tmp >>= 1
		digit += 1
	if a == 2 ** digit - 1:
		large_div = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
		return large_div[digit - 2]
	else:
		return 2 ** digit - 1

def main():
	q = int(input().strip())
	for _ in range(q):
		a = int(input().strip())
		print(f(a))
main()


import math

def solve(n):
	if n == 2:
		return 3
	bad = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
	if 2 ** math.floor(math.log2(n)) <= n <= 2 ** (math.floor(math.log2(n)) + 1) - 2:
		return 2 ** math.ceil(math.log2(n)) - 1
	else:
		return bad[math.floor(math.log2(n)) - 1]
q = int(input())
for i in range(q):
	print(solve(int(input())))


q = int(input())
b = [2 ** i - 1 for i in range(2, 26)]
a = [1 for i in range(2, 26)]
for i in range(len(b)):
	j = 2
	while j * j <= b[i]:
		if b[i] % j == 0:
			a[i] = b[i] // j
			break
		j += 1
for i in range(q):
	n = int(input())
	if n in b:
		print(a[b.index(n)])
	else:
		t = n
		x = 0
		while t > 0:
			t //= 2
			x *= 2
			x += 1
		print(x)


q = int(input())
for i in range(q):
	a = int(input())
	a_bin = format(a, 'b')
	if len(a_bin) == a_bin.count('1'):
		flag = 0
		for j in range(2, int(a ** (1 / 2)) + 2):
			if a % j == 0:
				print(a // j)
				flag = 1
				break
		if flag == 0:
			print(1)
	else:
		print(2 ** len(a_bin) - 1)


import math
q = int(input())
for u in range(q):
	a = int(input())
	if math.log2(a + 1) == int(math.log2(a + 1)):
		q = 1
		found = False
		while q < a ** 0.5:
			q += 1
			if a % q == 0:
				found = True
				break
		if found:
			print(a // q)
		else:
			print(1)
	else:
		print(2 ** math.ceil(math.log2(a + 1)) - 1)


from math import *
n = int(input())
bk = [pow(2, i) - 1 for i in range(1, 26)]
ans = [0, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
for i in range(n):
	m = int(input())
	l = len(bin(m)[2:])
	if bk.count(m) == 0:
		p = (1 << l) - 1
		p ^= m
		print(gcd(m ^ p, m & p))
	else:
		print(ans[l - 1])


import math
q = int(input())
for i in range(q):
	x = int(input())
	bin1 = bin(x)[2:]
	for i in bin1:
		if i == '0':
			print(2 ** len(bin1) - 1)
			break
	else:
		z = int(math.sqrt(x))
		for i in range(2, z + 1):
			if x % i == 0:
				print(x // i)
				break
		else:
			print(1)


from math import *
q = int(input())
ansarr = []
for l in range(q):
	n = int(input())
	b1 = bin(n)[2:]
	if b1.count('1') == len(b1):
		flag = 0
		for i in range(2, ceil(sqrt(n))):
			if n % i == 0:
				ansarr.append(n // i)
				flag = 1
				break
		if flag == 0:
			ansarr.append(1)
	else:
		i = len(b1)
		ansarr.append(2 ** i - 1)
print(*ansarr)


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def f(n):
	temp = n
	bit = 0
	one = 0
	while temp:
		bit += 1
		one += temp % 2
		temp //= 2
	if bit == one:
		div = n
		limit = int(math.sqrt(n + 1))
		for i in range(2, limit + 1):
			if n % i == 0:
				return n // i
		return 1
	return (1 << bit) - 1
q = inp()
for _ in range(q):
	n = inp()
	print(f(n))


import sys
n = int(input())
an = []
for i in range(n):
	p = int(sys.stdin.readline())
	q = bin(p)[2:]
	if len(set(q)) == 1:
		j = 2
		f = 1
		while j < int(p ** 0.5 + 2):
			if p % j == 0:
				f = max(j, p // j)
				break
			j = j + 1
		an.append(f)
	else:
		v = len(q)
		an.append(2 ** v - 1)
for v in an:
	print(v)


q = int(input())
pow2 = [2 ** i for i in range(30)]
for i in range(q):
	a = int(input())
	k = 0
	while pow2[k] <= a:
		k += 1
	if pow2[k] - 1 == a:
		p = 2
		n = 1
		while p * p <= a:
			if a % p == 0:
				n = max(n, a // p, p)
			p += 1
		print(n)
	else:
		print(pow2[k] - 1)


for _ in range(int(input())):
	n = int(input())
	b = bin(n)[2:]
	a = len(b)
	b = list(b)
	ans = ''
	for i in b:
		if i == '1':
			ans += '0'
		else:
			ans += '1'
	if a != b.count('1'):
		bn = int(ans, 2)
		print(bn ^ n)
	else:
		fans = 0
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				fans = max(fans, max(i, n // i))
		if fans == 0:
			print(1)
		else:
			print(fans)


q = int(input())
while q:
	a = int(input())
	b = a
	flag = False
	temp = 1
	while a:
		if a % 2 == 0:
			flag = True
		temp *= 2
		a //= 2
	if flag:
		print(temp - 1)
	else:
		i = 2
		rec = 1
		while i * i <= b:
			if b % i == 0:
				rec = b // i
				break
			i += 1
		print(rec)
	q -= 1


m = int(input())
for q in range(m):
	n = int(input())
	q1 = 1
	while q1 <= n:
		q1 *= 2
	if q1 != n + 1:
		print(q1 - 1)
	else:
		(p, f) = (bin(n)[2:], '')
		if len(p) % 2 == 0:
			f = '10' * (len(p) // 2 - 1) + '1'
			(q1, q2, ans) = (1, 0, 0)
			while q2 < len(f):
				ans += q1 * int(f[-q2 - 1])
				q2 += 1
				q1 *= 2
			print(ans)
		else:
			(q, d) = (2, 1)
			while q * q <= n:
				if n % q == 0:
					d = n // q
					break
				q += 1
			print(d)


import math
n = int(input())
for i in range(n):
	num = int(input())
	a = list(bin(num))
	b = a[2:]
	c = 0
	for j in range(len(b)):
		if b[j] == '0':
			b[j] = '1'
			c += 1
	if c == 0:
		text = ''.join(b)
		limit = int(math.sqrt(num))
		text = '1'
		for k in range(2, limit + 1):
			ans = num // k
			if num % k == 0:
				text = ans
				break
		print(text)
	else:
		text = ''.join(b)
		print(int(text, 2))


import math
q = int(input())
for i in range(q):
	a = int(input())
	if a & a + 1 == 0:
		was = False
		for i in range(3, int(math.sqrt(a) + 1)):
			if a % i == 0:
				was = True
				print(a // i)
				break
		if not was:
			print(1)
	else:
		if a & a - 1 == 0:
			a *= 2
		ans = math.ceil(math.log2(1.0 * a))
		ans = int(2 ** ans - 1)
		print(ans)


def isPrime(n):
	for i in range(3, n + 1):
		if n % i == 0:
			return i
ones = {}
ans = []
primes = {}
for i in range(2, 26):
	ones[2 ** i - 1] = 1
	ans.append(2 ** i - 1)
	primes[2 ** i - 1] = isPrime(2 ** i - 1)
t = int(input())
for z in range(t):
	n = int(input())
	if n not in ones:
		for i in ans:
			if i > n:
				print(i)
				break
	else:
		val = primes[n]
		print(n // val)


import math
q = int(input())
for _ in range(q):
	n = int(input())
	l = int(math.log2(n))
	l += 1
	if n + 1 == 2 ** l:
		ans = 1
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				ans = max(ans, n / i)
		print(int(ans))
	else:
		print(int(2 ** l - 1))


q = int(input())
for t in range(0, q):
	a = int(input())
	if a + 1 & a:
		print(2 ** a.bit_length() - 1)
	else:
		x = 2
		while a % x:
			if x * x > a:
				x = a
				break
			x = x + 1
		print(a // x)


def isprime(n):
	f = 1
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			f = i
			break
	return f
for _ in range(int(input())):
	a = int(input())
	b = bin(a)[2:]
	f = 0
	for i in b:
		if i == '0':
			f = 1
			break
	if f == 1:
		print(pow(2, len(b)) - 1)
	elif len(b) % 2 == 1:
		n = pow(2, len(b)) - 1
		fl = isprime(n)
		if fl == 1:
			print(1)
		else:
			print(n // fl)
	else:
		bi = ['0']
		for i in range(1, len(b)):
			bi.append('0' if bi[i - 1] == '1' else '1')
		print(int(''.join(bi), 2))


from math import sqrt
q = int(input())

def ntwo(n):
	t = 1
	while t <= n:
		t = t * 2
	return t - 1

def gg(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return n // i
	return 1
for u in range(q):
	a = int(input())
	c = ntwo(a)
	if c == a:
		print(gg(c))
	else:
		print(c)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(q,) = gil()
for _ in range(q):
	(v,) = gil()
	msb = int(log2(v))
	bit = 0
	for i in range(msb + 1):
		if v & 1 << i == 0:
			bit += 1 << i
	if bit:
		print(bit + v)
	else:
		ans = 1
		for i in range(2, ceil(sqrt(v)) + 1):
			if v % i == 0:
				ans = max(ans, v // i, i)
		print(ans)


import copy
import fractions
import itertools
import numbers
import string
import sys

def to_basex(num, x):
	while num > 0:
		yield (num % x)
		num //= x

def from_basex(it, x):
	ret = 0
	p = 1
	for d in it:
		ret += d * p
		p *= x
	return ret
lookup = {0: None, 1: None, 3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}

def core():
	ai = int(input())
	if ai in lookup:
		ans = lookup[ai]
	else:
		ans = ai
		while ans != ans | ans >> 1:
			ans = ans | ans >> 1
	print(ans)
q = int(input())
for _ in range(q):
	core()


from math import log, sqrt
for _ in range(int(input())):
	num = int(input())
	max_power = int(log(num, 2)) + 1
	if num == pow(2, max_power) - 1:
		max_b = 1
		for divisor in range(2, int(sqrt(num)) + 1):
			if num % divisor == 0:
				max_b = max(max_b, num // divisor)
		print(max_b)
	else:
		print(pow(2, max_power) - 1)


import math
q = int(input())
a = []
for i in range(q):
	a.append(int(input()))
for i in range(q):
	x = str(bin(a[i]))[2:]
	s = 0
	b = False
	for j in range(len(x)):
		if x[j] == '0':
			s += 2 ** (len(x) - j - 1)
			b = True
		else:
			s += 0
	if b:
		print(math.gcd(a[i] ^ s, a[i] & s))
	else:
		mx = 0
		for b in range(1, int(math.sqrt(a[i])) + 1):
			if a[i] % b == 0:
				if a[i] != b:
					mx = max(mx, b)
				if b != 1:
					mx = max(mx, a[i] // b)
		print(mx)


from math import gcd, log

def prime(n):
	a = [3, 7, 31, 127, 8191, 131071, 524287, 2147483647]
	if n in a:
		return 1
	else:
		return 0

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	a = []
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n):
		if prime[p]:
			a.append(p)
	return a
prim = SieveOfEratosthenes(10 ** 6)
t = int(input())
for i in range(t):
	a = int(input())
	p = int(log(a, 2))
	p = p + 1
	if p == log(a, 2):
		p = p + 1
	z = 2 ** p - 1
	if z == a:
		if prime(p):
			z = 1
		else:
			for i in prim:
				if z % i == 0:
					z = z // i
					break
	print(z)


import math

def oprime(a):
	chck = 0
	k = a
	f = 3
	l = []
	while chck == 0:
		if k == 3 or k == 5 or k == 7 or (k == 9):
			if k != 9:
				l.append(int(k))
				chck = 1
			else:
				l.append(3)
				l.append(3)
				chck = 1
		elif f > math.ceil(k / f):
			l.append(int(k))
			chck = 1
		elif k % f == 0:
			l.append(int(f))
			l.append(int(k / f))
			chck = 1
		elif k % f != 0:
			f += 2
	return l
n = int(input())
for k in range(1, n + 1):
	x = int(input())
	p = 0
	y = str(bin(x))
	y = y.lstrip('0b')
	l = len(y)
	if '0' in y:
		print(2 ** l - 1)
	else:
		j = oprime(x)
		if len(j) == 2:
			print(j[1])
		else:
			print(1)


dic = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
l = [3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863]

def f(i):
	for j in l:
		if j == i:
			return dic[j]
		elif j > i:
			return j
n = int(input())
for query in range(n):
	print(f(int(input())))


import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	a = int(input())
	bit = a.bit_length()
	b = 2 ** bit - 1
	if a == b:
		b = 1
		for j in range(2, int(math.floor(math.sqrt(a))) + 1):
			if a % j == 0:
				b = a // j
				break
	print(b)


q = int(input())
for _ in range(q):
	n = int(input())
	m = n
	s = ''
	mp = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
	while n > 0:
		s = s + str(1 - int(n % 2))
		n //= 2
	if s.count('1') == 0:
		print(mp[len(s) - 2])
	else:
		print(pow(2, len(s)) - 1)


import sys
import math
lines = sys.stdin.read().splitlines()
n = [int(x) for x in lines[0].split()]

def isPowerOfTwo(n):
	m = 2
	while m <= n:
		if m == n:
			return True
		m *= 2

def getPowerOfTwo(n):
	m = 2
	while m <= n:
		m *= 2
	return m

def findPrimes(n):
	primes = [2]
	yield 2
	for i in range(3, n, 2):
		isPrime = True
		for prime in primes:
			if i % prime == 0:
				isPrime = False
				break
			if prime ** 2 > i:
				break
		if isPrime:
			yield i
			primes.append(i)

def getLowestPrimeDiv(n):
	for p in findPrimes(n):
		if n % p == 0:
			return p
		if p ** 2 > n:
			return 1
mersenne = [2 ** x - 1 for x in [5, 7, 13, 17, 19]]
for i in lines[1:]:
	number = [int(x) for x in i.split()][0]
	if isPowerOfTwo(number + 1):
		if number in mersenne:
			print(1)
		else:
			div = getLowestPrimeDiv(number)
			if div == 1:
				print(div)
			else:
				print(number // getLowestPrimeDiv(number))
	else:
		print(getPowerOfTwo(number) - 1)


def gcd(a, b):
	if b > a:
		return gcd(b, a)
	if b == 0:
		return a
	if a % b == 0:
		return b
	return gcd(b, a % b)

def f(a):
	best = -1
	tag = None
	for b in range(1, a):
		d = gcd(a ^ b, a & b)
		if d > best:
			best = d
			tag = b
	return (best, tag)

def f2(a):
	for b in range(a - 1, 0, -1):
		if a % b == 0:
			return b
special = dict()
special = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
q = int(input())
for test in range(q):
	a = int(input())
	if a in special:
		print(special[a])
	else:
		length = len(bin(a)) - 2
		print(2 ** length - 1)


from math import *
from operator import xor

def bruteforce(n):
	mx = 0
	for i in range(1, n):
		mx = max(mx, gcd(xor(i, n), i & n))
	print(mx)

def find_great_div(n):
	ans = 1
	for i in range(2, n):
		if i * i > n:
			break
		if n % i == 0:
			ans = max(ans, i)
			ans = max(ans, n // i)
	print(ans)

def solve(n):
	base = int(ceil(log2(n + 1)))
	num = int(pow(2, base)) - 1
	if n == num:
		find_great_div(n)
	else:
		print(num)
testcase = int(input())
while testcase:
	testcase -= 1
	n = int(input())
	solve(n)


def largest_proper_divisor(n):
	d = 2
	while d * d <= n:
		if n % d == 0:
			return d
		d += 1
	return n
for t in range(int(input())):
	a = int(input())
	n = 1
	while n <= a:
		n <<= 1
	n -= 1
	if a == n:
		print(n // largest_proper_divisor(n))
	else:
		print(n)


q = int(input())
A = [1] * 26
for i in range(1, 26):
	for j in range(2, int((2 ** i - 1) ** 0.5) + 1):
		if (2 ** i - 1) % j == 0:
			A[i] = (2 ** i - 1) // j
			break
for i in range(q):
	n = int(input())
	s = bin(n)[2:]
	if s != '1' * len(s):
		print(2 ** len(s) - 1)
	else:
		print(A[len(s)])


import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
b = [2 ** i for i in range(30)]
c = []
ans = [1, 1, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401, 22369621, 19173961, 89478485, 2304167]
for i in range(30):
	c.append(b[i] - 1)
for i in range(n):
	if a[i] in c:
		print(ans[c.index(a[i])])
	else:
		j = 0
		while b[j] <= a[i]:
			j += 1
		print(c[j])


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def primes(n):
	sieve = [True] * n
	z = int(n ** 0.5) + 1
	for i in range(3, z, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [i for i in range(3, n, 2) if sieve[i]]
P = primes(pow(2, 14))

def solve():
	N = getInt()
	if '0' in bin(N)[2:]:
		two_pow = 2
		while two_pow <= N:
			two_pow *= 2
		return two_pow - 1
	for i in P:
		if N % i == 0:
			return N // i
	return 1
for _ in range(getInt()):
	print(solve())


from math import ceil, log, floor, sqrt

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_product(n, m, arr):
	product = 1
	if n <= m:
		for i in range(n):
			for j in range(i + 1, n):
				product = product * abs(arr[i] - arr[j]) % m
		return product
	return 0

def count_tables(l):
	count = 0
	l.sort()
	a = l[1] - l[0]
	b = l[2] - l[0]
	if a % 3 > 0 and a % 3 + (b - (a - a % 3)) >= 3:
		count += 1
	count += l[0] + 2 * a // 3
	return int(min(sum(l) / 3, l[0] + l[1]))

def find_possible_weight(W, arr):
	w = 0
	for i in range(8, 0, -1):
		count = min(arr[i - 1], W // i)
		w += count * i
		W -= count * i
	return w

def find_divisor(a):
	divisors = []
	divisors.append(1)
	for i in range(2, min(a, ceil(sqrt(a)) + 1)):
		if a % i == 0:
			if a / i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(a / i)
	return int(max(divisors))

def find_max_gcd(a):
	degree = ceil(log(a) / log(2))
	m = pow(2, degree) - 1
	if a == m:
		return find_divisor(a)
	if a == m + 1:
		m = 2 * a - 1
	return m
t = 1
t = int(input())
while t:
	t = t - 1
	n = int(input())
	print(find_max_gcd(n))


l = int(input())
str = []
for i in range(l):
	str.append(int(input()))
step = []
for i in range(2, 26):
	step.append(2 ** i - 1)
nod = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
for i in range(l):
	for j in range(len(step)):
		if str[i] < step[j]:
			print(step[j])
			break
		elif str[i] == step[j]:
			print(nod[j])
			break


Q = int(input())
A = [int(input()) for i in range(Q)]
L = set([(1 << i) - 1 for i in range(26)])
K = [0, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]

def f(a):
	if a not in L:
		s = len(bin(a)) - 2
		return (1 << s) - 1
	else:
		for i in range(26):
			if a == (1 << i) - 1:
				break
		return K[i - 1]
for a in A:
	print(f(a))


n = int(input())
for j in range(n):
	a = int(input())
	i = 1
	while i <= a:
		i *= 2
	if a != i - 1:
		print(i - 1)
	else:
		q = 2
		while a % q != 0 and q * q <= a:
			q += 1
		if a % q != 0:
			print(1)
		else:
			print(a // q)


import math
n = int(input())
powers = [0, 1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
for i in range(n):
	q = int(input())
	x = int(math.log(q, 2)) + 1
	y = 2 ** x - 1
	if y == q:
		y = powers[x - 1]
	print(y)


import math

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def main():
	t = int(input())
	while t > 0:
		t -= 1
		n = int(input())
		if isPowerOfTwo(n + 1):
			s = math.ceil(math.sqrt(n))
			ans = 1
			for i in range(2, s + 1):
				if n % i == 0:
					ans = n / i
					break
			ans = int(ans)
			print(math.gcd(n ^ ans, n & ans))
		else:
			z = bin(n)[2:]
			newstr = ''
			for i in range(len(z)):
				newstr += '1'
			z = int(newstr, 2)
			print(z)
main()


import math
n = int(input())
for _ in range(n):
	i = int(input())
	k = 2 ** (int(math.log2(i)) + 1) - 1
	if i != k:
		print(k)
	else:
		for j in range(2, int(math.sqrt(i)) + 1):
			if i % j == 0:
				print(i // j)
				break
		else:
			print(1)


_except = {1: 0, 2: 1, 3: 1, 4: 5, 5: 1, 6: 21, 7: 1, 8: 85, 9: 73, 10: 341, 11: 89, 12: 1365, 13: 1, 14: 5461, 15: 4681, 16: 21845, 17: 1, 18: 87381, 19: 1, 20: 349525, 21: 299593, 22: 1398101, 23: 178481, 24: 5592405, 25: 1082401}
regular = {1: 1, 2: 3, 3: 7, 4: 15, 5: 31, 6: 63, 7: 127, 8: 255, 9: 511, 10: 1023, 11: 2047, 12: 4095, 13: 8191, 14: 16383, 15: 32767, 16: 65535, 17: 131071, 18: 262143, 19: 524287, 20: 1048575, 21: 2097151, 22: 4194303, 23: 8388607, 24: 16777215, 25: 33554431}

def e(n):
	temp = 0
	magic = True
	while n >= 1:
		if n % 2 == 0:
			magic = False
		temp = temp + 1
		n = n // 2
	return (magic, temp)

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def temp_test(n):
	_max = 0
	token = 0
	for i in range(1, n // 2 + 1):
		_ = gcd(n - i, i)
		if _ > _max:
			_max = _
			token = i
	token_info = e(token)
	return (_max, token, token_info)
q = input()
q = int(q)
round = 0
while round < q:
	a = input()
	a = int(a)
	(magic, info) = e(a)
	print(_except[info] if magic else regular[info])
	round = round + 1


from math import sqrt as S

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(int(input())):
	a = int(input())
	if a & a + 1 == 0:
		b = 1
		for i in range(2, int(S(a)) + 1):
			if a % i == 0:
				b = max(b, a // i, i)
		print(gcd(a ^ b, a & b))
	else:
		b = list(bin(a)[2:])
		for i in range(len(b)):
			if b[i] == '1':
				b[i] = '0'
			else:
				b[i] = '1'
		b = ''.join(b)
		b = int(b, 2)
		print(gcd(a ^ b, a & b))


import math

def fact(n):
	maxa = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			maxa = max(maxa, i)
			if n // i != n:
				maxa = max(maxa, n // i)
	return maxa
a = int(input())
for i in range(a):
	x = int(input())
	r = bin(x)
	r = r[2:]
	if r.count('0') != 0:
		print(pow(2, len(r)) - 1)
	else:
		print(fact(x))


from sys import stdin
from math import log
q = int(stdin.readline().strip())

def div(n):
	maxx = 0
	i = 1
	lim = n ** 0.5
	while i <= lim:
		if n % i == 0:
			if n / i == i:
				if i != n:
					maxx = max(maxx, i)
			else:
				if i != n:
					maxx = max(maxx, i)
				if n / i != n:
					maxx = max(maxx, n // i)
		i = i + 1
	return maxx
for i in range(q):
	n = int(stdin.readline().strip())
	x = 2 ** (int(log(n, 2)) + 1)
	if n == x - 1:
		print(div(n))
	else:
		print(-1 + 2 ** (int(log(n, 2)) + 1))


s = input()
n = int(s)
for i in range(n):
	s = input()
	a = int(s)
	s = bin(a)
	cnt0 = s.count('0') - 1
	l = len(s) - 2
	if cnt0 > 0:
		print(2 ** l - 1)
	else:
		p = [2, 3, 5, 7, 13, 17, 19]
		if l in p:
			print(1)
		else:
			for i in range(3, a):
				if a % i == 0:
					print(a // i)
					break


from math import gcd, sqrt, log

def isPower(num, base):
	power = int(log(num, base) + 0.5)
	return base ** power == num
for _ in range(int(input())):
	a = int(input())
	ans = bin(a).split('b')[1]
	if isPower(a + 1, 2):
		flag = False
		for x in range(2, int(sqrt(a // 2)) + 2):
			if a % x == 0:
				ans = a // x
				flag = True
				break
		print(ans if flag else 1)
	else:
		new = '0b'
		b = bin(a).split('b')[1]
		for x in b:
			if x is '1':
				new += '0'
			else:
				new += '1'
		b = int(new, 2)
		print(gcd(a ^ b, a & b))


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
q = int(input())
for i in range(q):
	a = int(input())
	b = a
	c = 0
	while a != 0:
		a = a // 2
		c += 1
	ans = 2 ** c - 1
	if ans == b:
		print(ans // smallestDivisor(ans))
	else:
		print(ans)


n = int(input())
precalc = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
n2 = [1]
for i in range(25):
	n2.append(n2[-1] * 2)
n2 = [t - 1 for t in n2 if t - 1 >= 2]
while n:
	n -= 1
	a = int(input())
	i = 0
	while i < len(n2):
		if n2[i] >= a:
			break
		i += 1
	if a == n2[i]:
		print(precalc[i])
	else:
		print(n2[i])


from __future__ import print_function
from itertools import permutations as perm
from functools import cmp_to_key
from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	if n & n + 1:
		msb = int(log2(n)) + 1
		ans = 1 << msb
		print(ans - 1)
		continue
	maxFactor = 1
	for fac in range(2, ceil(sqrt(n)) + 1):
		if n % fac == 0:
			maxFactor = max(maxFactor, fac, n // fac)
	print(gcd(n & maxFactor, n ^ maxFactor))


from math import *
curr = 1
ans = [0] * 26
for i in range(1, 26):
	num = (1 << curr) - 1
	curr += 1
	j = 1
	l = []
	while j * j <= num:
		if j * j == num:
			l.append(j)
		elif num % j == 0:
			l.append(j)
			l.append(num // j)
		j += 1
	mx = 0
	l.remove(num)
	for k in l:
		mx = max(mx, gcd(k ^ num, num & k))
	ans[i] = mx
t = int(input())
for _ in range(t):
	n = int(input())
	s = bin(n)
	s = s[2:]
	if s.count('0') > 0:
		print((1 << len(s)) - 1)
	else:
		print(ans[len(s)])


import math
q = int(input())
while q > 0:
	n = int(input())
	len = 0
	while 2 ** len <= n:
		len += 1
	if n != 2 ** len - 1:
		print(2 ** len - 1)
	else:
		i = 1
		mx = 1
		while i * i <= n:
			if n % i == 0:
				mx = max(i, mx)
				if i != 1:
					mx = max(n // i, mx)
			i += 1
		print(int(mx))
	q -= 1


primethaticare = set([0, 1, 3, 7, 31, 127, 8191, 131071, 524287])
notpowerof2 = set([2 ** i - 1 for i in range(27)])
divisibleby3 = set([0, 3, 15, 63, 255, 1023, 4095, 16383, 65535, 262143, 1048575, 4194303, 16777215])
specialcase = [511, 2047, 32767, 524287, 2097151, 8388607, 33554431]

def largestfactor(x):
	original = x
	for i in range(2, int(original ** 0.5) + 1):
		if x % i == 0:
			return x // i
for i in range(int(input())):
	N = int(input())
	total = 0
	something = list(bin(N))
	something = something[2:]
	something.reverse()
	if N not in notpowerof2:
		for i in range(len(something)):
			if something[i] == '0':
				total += 2 ** i
		print(total + N)
	elif N in primethaticare:
		print('1')
	else:
		print(largestfactor(N))


def bit(x, i):
	return x >> i & 1

def find_div(x):
	ans = 1
	for i in range(2, x):
		if x % i == 0:
			ans = max(ans, x // i, i)
		if i * i >= x:
			return ans

def is_all1(x):
	for i in range(26):
		if 1 << i > x:
			return True
		if bit(x, i) == 0:
			return False

def cnt_bit(x):
	cnt = 0
	while 1 << cnt <= x:
		cnt += 1
	return cnt

def ask_ans(x):
	if is_all1(x):
		return find_div(x)
	cnt = cnt_bit(x)
	ans = 0
	was1 = False
	for i in range(cnt - 1, -1, -1):
		if was1:
			if bit(x, i) == 0:
				ans |= 1 << i
		elif bit(x, i):
			was1 = True
	return ans | x

def main():
	q = int(input())
	a = []
	for i in range(q):
		a.append(int(input()))
	for x in a:
		print(ask_ans(x))
main()


import math
n = int(input())
while n > 0:
	k = int(input())
	z = int(math.sqrt(k))
	if int(math.log(k + 1, 2)) == math.log(k + 1, 2):
		r = 0
		for i in range(2, z + 1):
			if k % i == 0:
				print(k // i)
				r = 1
				break
		if r != 1:
			print('1')
	else:
		print(2 ** (int(math.log(k + 1, 2)) + 1) - 1)
	n -= 1


import math

def pr(n):
	a = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				a.append(int(i))
			else:
				a.extend([i, n // i])
		i = i + 1
	return sorted(a, reverse=True)
t = int(input())
for i in range(t):
	n = int(input())
	i = 1
	while 1 > 0:
		if 2 ** i > n:
			break
		i += 1
	if 2 ** i - n == 1:
		a = pr(n)
		if len(a) == 2:
			print(1)
		else:
			print(a[1])
	else:
		print(2 ** i - 1)


def inint():
	return int(input())

def mp():
	return map(int, input().split())
use = {1: 0, 3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
for _ in range(inint()):
	a = inint()
	if a in use:
		print(use[a])
		continue
	print(2 ** (len(bin(a)) - 2) - 1)


def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x

def main():
	n = int(input())
	for i in range(n):
		x = int(input())
		strbin = format(x, 'b')
		strbinR = strbin[::-1]
		while strbinR[len(strbinR) - 1] == '0':
			strbinR = strbinR[0:len(strbinR) - 2]
		cnt1 = 0
		flag = 0
		ans = 1
		final = ''
		for j in range(len(strbinR)):
			if j + 1 == len(strbinR) and strbinR[j] == '1' and (cnt1 == 0):
				d = 2
				flag = 1
				while d * d <= x:
					if x % d == 0:
						ans = x // d
						break
					d += 1
			if strbinR[j] == '1':
				final += '0'
			else:
				final += '1'
				cnt1 += 1
		if flag == 1:
			print(ans)
			continue
		print(gcd(x & int(final[::-1], 2), x ^ int(final[::-1], 2)))
main()


from math import log
q = int(input())
for i in range(q):
	w = int(input())
	if log(w + 1, 2) > int(log(w + 1, 2)):
		print(2 ** (int(log(w + 1, 2)) + 1) - 1)
	else:
		c = w
		p = 3
		k = False
		while k == False and p <= int(w ** 0.5):
			if w % p == 0:
				k = True
				c = p
			else:
				p += 2
		print(w // c)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans

def get_large(x):
	for n in range(2, math.ceil(math.sqrt(x))):
		if x % n == 0:
			return x // n
	return 1
a = [1]
for i in range(32):
	a.append(a[-1] * 2)
b = []
for aa in a:
	b.append(aa - 1)
t = int(input())
for tt in range(t):
	n = int(input())
	flag = 0
	for i in range(len(a)):
		if a[i] == n:
			print(a[i + 1] - 1)
			flag = 1
			break
		if a[i] > n:
			break
	if flag:
		continue
	for i in range(len(b)):
		if b[i] == n:
			fc = get_large(n)
			print(math.gcd(n ^ fc, n & fc))
			flag = 1
			break
	if flag:
		continue
	for i in range(len(b)):
		if b[i] > n:
			print(b[i])
			break
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


import math
amount = int(input())
for i in range(amount):
	number = int(input())
	copy = number
	array = []
	while number > 1:
		array.append(number % 2)
		number = number // 2
	array.append(1)
	array = array[::-1]
	if sum(array) == len(array):
		sum_ = 1
		for i in range(1, int(copy ** (1 / 2)) + 1):
			if copy % i == 0 and copy // i != copy:
				sum_ = copy // i
				break
	else:
		sum_ = 0
		for i in range(len(array) - 1, -1, -1):
			sum_ += 2 ** i
	print(sum_)


def mp():
	return map(int, input().split())

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
n = int(input())
for i in range(n):
	a = int(input())
	x = a
	s = []
	while x > 0:
		s.append(str(1 - x % 2))
		x //= 2
	s = ''.join(s[::-1])
	b = int(s, 2)
	if b != 0:
		print(a ^ b)
	else:
		c = [0] * 26
		c[1] = 1
		c[2] = 1
		c[3] = 1
		c[4] = 5
		c[5] = 1
		c[6] = 21
		c[7] = 1
		c[8] = 85
		c[9] = 73
		c[10] = 341
		c[11] = 89
		c[12] = 1365
		c[13] = 1
		c[14] = 5461
		c[15] = 4681
		c[16] = 21845
		c[17] = 1
		c[18] = 87381
		c[19] = 1
		c[20] = 349525
		c[21] = 299593
		c[22] = 1398101
		c[23] = 178481
		c[24] = 5592405
		c[25] = 1082401
		print(c[len(s)])


import math

def onesComplement(n):
	number_of_bits = int(math.floor(math.log(n) / math.log(2))) + 1
	return (1 << number_of_bits) - 1 ^ n

def primeFactors(n):
	while n % 2 == 0:
		return (2,)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			return i
			n = n / i
	if n > 2:
		return n
n = 315
primeFactors(n)
q = int(input())
for i in range(q):
	n = int(input())
	max = 0
	if onesComplement(n) != 0:
		print(n ^ onesComplement(n))
	else:
		max1 = 0
		if n % 3 == 0:
			print(n // 3)
		else:
			print(n // primeFactors(n))


cheat = [1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401]
q = int(input())
for i in range(q):
	a = int(input())
	if a.bit_length() == (a + 1).bit_length():
		print((1 << a.bit_length()) - 1)
	else:
		print(cheat[a.bit_length() - 2])


import math

def fact(n):
	i = 1
	f = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				f.append(i)
			else:
				f.append(i)
				f.append(n // i)
		i = i + 1
	return sorted(f)[-2]
for _ in range(int(input())):
	a = int(input())
	k = 0
	s = 0
	for i in bin(a)[2:][::-1]:
		if i == '0':
			s += pow(2, k)
		k += 1
	if s > 0:
		print(pow(2, k) - 1)
	else:
		print(fact(a))


q = int(input())
nums = [2] * 25
for i in range(1, 25):
	nums[i] = nums[i - 1] * 2
while q > 0:
	a = int(input())
	flag = 0
	for i in range(25):
		if a + 1 == nums[i]:
			flag = 1
			break
	if flag:
		num = bin(a)[2:]
		if len(num) % 2 != 0:
			n = len(num)
			if n == 9:
				print(73)
			elif n == 11:
				print(89)
			elif n == 15:
				print(4681)
			elif n == 21:
				print(299593)
			elif n == 23:
				print(178481)
			elif n == 25:
				print(1082401)
			else:
				print(1)
		else:
			ans = 0
			num2 = 1
			for i in range(len(num)):
				if i % 2 == 0:
					ans += num2
				num2 *= 2
			print(ans)
	else:
		num = bin(a)[2:]
		num2 = 1
		ans = 0
		for i in num:
			ans += num2
			num2 *= 2
		print(ans)
	q -= 1


for i in range(int(input())):
	n = int(input())
	lol = str(bin(n))[2:]
	if '0' in lol:
		print(2 ** len(lol) - 1)
	else:
		fl = 0
		hom = 2 ** len(lol) - 1
		for z in range(3, int(hom ** 0.5) + 1):
			if hom % z == 0:
				print(hom // z)
				fl = 1
				break
		if not fl:
			print(1)


l = {}
ll = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, b % a)
q = int(input())
for i in range(q):
	x = int(input())
	if x in ll.keys():
		print(ll[x])
		continue
	y = 0
	for j in range(30):
		xx = 2 ** j
		if xx & x:
			y = j
	y += 1
	ans = 2 ** y - 1
	print(ans)


q = int(input())
for i in range(q):
	a = int(input())
	a2 = bin(a)[2:]
	if a2 == a2[0] * len(a2):
		d = 2
		f = 0
		while d ** 2 <= a:
			if a % d == 0:
				print(a // d)
				f = 1
				break
			d += 1
		if f == 0:
			print(1)
	else:
		print(2 ** len(a2) - 1)


def su(l):
	ans = 0
	for i in range(l):
		ans = ans + pow(2, i)
	return ans

def abc(x):
	ans = 0
	p = int(x ** 0.5)
	for i in range(2, p + 1):
		if x % i == 0:
			return x // i
	return 1
for _ in range(int(input())):
	x = int(input())
	b = bin(x)
	b = b[2:]
	p = b.count('0')
	if p == 0:
		print(abc(x))
	else:
		print(su(len(b)))


import math
pa = [2 ** i for i in range(1, 26)]
for i in range(int(input())):
	a = input()
	a = int(a)
	if a == 2:
		print(3)
	elif a == 3:
		print('1')
	elif a + 1 in pa:
		for i in range(2, int(math.sqrt(a) + 1) + 1):
			if a % i == 0:
				print(a // i)
				break
		else:
			print(1)
	else:
		for i in pa:
			if i > a:
				break
		print(i - 1)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import *
import functools
import sys
import math
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()
t = [0] * 1000010

def create(a, n):
	global t
	for i in range(n, 2 * n):
		t[i] = a[i - n]
	for i in range(n - 1, 0, -1):
		t[i] = t[2 * i] + t[2 * i + 1]

def ncr(n, k):
	res = 1
	c = [0] * (k + 1)
	c[0] = 1
	for i in range(1, n + 1):
		for j in range(min(i, k), 0, -1):
			c[j] = (c[j] + c[j - 1]) % MOD
	return c[k]
d = {3: 1, 7: 1, 15: 5, 31: 1, 63: 21, 127: 1, 255: 85, 511: 73, 1023: 341, 2047: 89, 4095: 1365, 8191: 1, 16383: 5461, 32767: 4681, 65535: 21845, 131071: 1, 262143: 87381, 524287: 1, 1048575: 349525, 2097151: 299593, 4194303: 1398101, 8388607: 178481, 16777215: 5592405, 33554431: 1082401}
for _ in range(int(input())):
	n = int(input())
	if d.get(n):
		print(d[n])
	else:
		print(int('1' * len(bin(n)[2:]), 2))