#include <bits/stdc++.h>
using namespace std;
int lowbit(int x) { return x & (-x); }
int highbit(int x) {
  if (x == 0)
    return 0;
  else if (x == 1)
    return 1;
  else
    return highbit(x >> 1) << 1;
}
int mx(int x) {
  int tmp = x, mn = x, c = (int)sqrt(x);
  for (int i = 2; i <= c; ++i) {
    if (x % i == 0) {
      mn = i;
      break;
    }
  }
  return x / mn;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int a;
    scanf("%d", &a);
    if (lowbit(a + 1) == a + 1) {
      printf("%d\n", mx(a));
    } else {
      printf("%d\n", (highbit(a) << 1) - 1);
    }
  }
}
