fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(a) a.begin(), a.end()
  4. #define ll long long
  5. #define fo(i,n) for (long long i = 0; i < n; i++)
  6. #define pb push_back
  7. bool check(ll x)
  8. {
  9. x++;
  10. return ((x & (x-1)) == 0 );
  11. }
  12. int main()
  13. {
  14. ll a,b,c,d,n,m,k,input,i,x;
  15. ios_base::sync_with_stdio(false);
  16. string sinput;
  17. cin.tie(0); cout.tie(0);
  18. cin >> i;
  19. while (i--)
  20. {
  21. cin >> x;
  22. ll y = x-1;
  23. if (x < 5 || check(x) || check(x-1))
  24. {
  25. cout << -1 << '\n';
  26. continue;
  27. }
  28. if ((x ^ y) == 1)
  29. {
  30. ll count = 0;
  31. ll de = x;
  32. while (de > 1)
  33. {
  34. de = de / 2;
  35. count++;
  36. }
  37. y = (1 << count) - 1;
  38. }
  39. cout << y << '\n';
  40. }
  41. }
Success #stdin #stdout 0.01s 5280KB
stdin
7
5
2
6
3
69
4
8
stdout
3
-1
5
-1
63
-1
-1