#include #include #include using namespace std; vector> Prime_Factorization(long long n) { vector> v; if (n == 1) { v.push_back(make_pair(1, 1)); return v; } long long k = 2; while (k * k <= n) { if (n % k == 0) { long c = 0; while (n % k == 0) { c++; n /= k; } v.push_back(make_pair(k, c)); } k++; } if (n != 1) { v.push_back(make_pair(n, 1)); } return v; } long long power(long long a, long long n) { long long ans = 1; long long x = a; while (n > 0) { if (n % 2 == 1) { ans *= x; } x *= x; n /= 2; } return ans; } long long power_mod(long long a, long long n, long long m) { long long ans = 1; long long x = a % m; while (n > 0) { if (n % 2 == 1) { ans = (ans * x) % m; } x = (x * x) % m; n /= 2; } return ans; } long long Euler_Totient(long long n) { if (n == 1) { return 1; } vector> p; p = Prime_Factorization(n); long long R = 1; for (int i = 0; i < p.size(); i++) { R *= power(p.at(i).first, p.at(i).second - 1) * (p.at(i).first - 1); } return R; } vector Divisors(long long n) { vector u, v; long long k = 1; while (k * k <= n) { if (n % k == 0) { u.push_back(k); if (k != n / k) { v.push_back(n / k); } } k++; } reverse(begin(v), end(v)); u.insert(u.end(), v.begin(), v.end()); return u; } int main() { int T; cin >> T; for (int j = 0; j < T; j++) { long long a = 1; long long ans = 0; long long N; cin >> N; long long M = 2 * N - 1; long long phi = Euler_Totient(M); vector v = Divisors(phi); reverse(begin(v), end(v)); for (int i = 0; i < v.size(); i++) { if ((power_mod(2, v.at(i), M) - 1) % M == 0) { ans = v.at(i); } } cout << ans << endl; } }