/* -*- coding: utf-8 -*- * * 3102.cc: No.3102 floor sqrt xor - yukicoder */ #include #include #include using namespace std; /* constant */ /* typedef */ using ll = long long; /* global variables */ /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { ll n; scanf("%lld", &n); if (n == 0) { puts("0"); continue; } if (n == 1) { puts("-1"); continue; } ll x0 = (n >> 30) << 30, x1 = ((n >> 30) + 1) << 30; int s0 = sqrt(0.5 + x0), s1 = sqrt(0.5 + x1); ll k = -1; for (int s = s0; s <= s1; s++) { ll sk = n ^ s; if (sk >= (ll)s * s && sk < (ll)(s + 1) * (s + 1)) { k = sk; break; } } printf("%lld\n", k); } return 0; }