fork download
  1. // بسم الله الرحمن الرحيم
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto &i : v) os << i << ' '; return os; }
  7. template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; }
  8. #define endl '\n'
  9. #define int long long
  10. #define ull unsigned long long
  11. #define pii pair<int, int>
  12. #define vi vector<int>
  13. #define all(v) v.begin(), v.end()
  14. #define allr(v) v.rbegin(), v.rend()
  15. #define Num_of_Digits(n) ((int(log10(n)) + 1))
  16.  
  17. #define ElgamalyHowaAmaly ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(10)
  18.  
  19.  
  20. set<int> gameOver;
  21.  
  22. void solve1()
  23. {
  24. int x; cin >> x;
  25. if(gameOver.count(x)){
  26. cout << -1 << endl;
  27. return;
  28. }
  29. int msb = log2(x-1);
  30. int y = (1ll << msb);
  31. while(y + (y ^ x) <= x) --y;
  32. cout << y << endl;
  33.  
  34. }
  35.  
  36. signed main(){
  37.  
  38. ElgamalyHowaAmaly;
  39.  
  40. int x = 1;
  41. for(int i = 2; x <= 1e9; i *= 2) gameOver.insert(x), x += i;
  42. for(int i = 1; (1ll << i) <= 1e9; ++i) gameOver.insert(1ll << i);
  43.  
  44. int t = 1;
  45. cin >> t;
  46. for(int test = 1; test <= t; ++test)
  47. {
  48. solve1();
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
4194303