#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; // cout << fixed << setprecision(10); const ll INF = 4e18; const ld PI = acos(-1); #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define elif else if #define add insert #define ctoll(x) static_cast(x - '0') #define lltos(x) to_string(x) #define lltoc(x) static_cast(x + '0') #define all(v) (v).begin(),(v).end() #define len(v) ll(v.size()) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) template T SUM(const vector &v) { T total = 0; for(int i = 0; i < len(v); i++) total += v[i]; return total; } #define OVERLOAD_SORT(_1, _2, name, ...) name #define SORT1(x) stable_sort((x).begin(), (x).end()) #define SORT2(x, idx) stable_sort(all(x), [&](const vector &_a_, const vector &_b_){return _a_[idx] < _b_[idx];}) #define SORT(...) OVERLOAD_SORT(__VA_ARGS__, SORT2, SORT1)(__VA_ARGS__) #define OVERLOAD_RSORT(_1, _2, name, ...) name #define RSORT1(x) stable_sort((x).rbegin(), (x).rend()) #define RSORT2(x, idx) stable_sort((x).rbegin(), (x).rend(), [&](const vector &_a_, const vector &_b_){return _a_[idx] < _b_[idx];}) /* #define RSORT2(x, idx) stable_sort((x).rbegin(), (x).rend(), [&](const vector &_a_, const vector &_b_){ \ if (_a_[1] == _b_[1]) { \ return _a_[0] > _b_[0]; \ } \ return _a_[1] < _b_[1]; }) */ #define RSORT(...) OVERLOAD_RSORT(__VA_ARGS__, RSORT2, RSORT1)(__VA_ARGS__) template void rev(T &v) { reverse((v).begin(), (v).end()); } #define uniq(v) \ SORT(v), v.erase(unique(all(v)), v.end()), v.shrink_to_fit() template void chmin(T& a, T b) { a = min(a, b); } template void chmax(T& a, T b) { a = max(a, b); } template bool contain(const std::string& s, const T& v) { return s.find(v) != std::string::npos; } #define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name #define REP1(i, n) for (auto i = std::decay_t{}; (i) != (n); ++(i)) #define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i)) #define REP3(i, l, r, s) for (auto i = (l); (i) < (ll)(r); (i) += s) #define rep(...) OVERLOAD_REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__) #define rrep(i, a, b) for(int i = a; i >= b; i--) #define OVERLOAD_FORE(_1, _2, _3, name, ...) name #define FORE1(i, a) for(auto &i : a) #define FORE2(i, j, a) for(auto &[i, j] : a) #define fore(...) OVERLOAD_FORE(__VA_ARGS__, FORE2, FORE1)(__VA_ARGS__) using vl = vector; using vvl = vector>; using vvvl = vector>>; using vs = vector; template using uset = unordered_set; template using mset = multiset; #define discard(s, x) {auto itr_ = s.find((x)); if (itr_ != s.end()) s.erase(itr_); } template using mmap = multimap; template using umap = unordered_map; template using pq = priority_queue; template using pqg = priority_queue, greater>; // 昇順 // unordered_set, unordered_multiset, unordered_map, unordered_multimap で pair, vector, tuple を key に設定させる template size_t HashCombine(const size_t seed,const T &v){ return seed^(std::hash()(v)+0x9e3779b9+(seed<<6)+(seed>>2)); } /* pair用 */ template struct std::hash>{ size_t operator()(const std::pair &keyval) const noexcept { return HashCombine(std::hash()(keyval.first), keyval.second); } }; /* vector用 */ template struct std::hash>{ size_t operator()(const std::vector &keyval) const noexcept { size_t s=0; for (auto&& v: keyval) s=HashCombine(s,v); return s; } }; /* tuple用 */ template struct HashTupleCore{ template size_t operator()(const Tuple &keyval) const noexcept{ size_t s=HashTupleCore()(keyval); return HashCombine(s,std::get(keyval)); } }; template <> struct HashTupleCore<0>{ template size_t operator()(const Tuple &keyval) const noexcept{ return 0; } }; template struct std::hash>{ size_t operator()(const tuple &keyval) const noexcept { return HashTupleCore>::value>()(keyval); } }; // bisect // vector template int bisect_left(vector &X, T v){ return lower_bound(X.begin(), X.end(), v) - X.begin(); } template int bisect_right(vector &X, T v){ return upper_bound(X.begin(), X.end(), v) - X.begin(); } // set template T set_bisect_left(set &X, T v){ auto itr = X.lower_bound(v); T obj = *itr; return obj; } template T set_bisect_right(set &X, T v){ auto itr = X.upper_bound(v); T obj = *itr; return obj; } // multiset template T mset_bisect_left(mset &X, T v){ auto itr = X.lower_bound(v); T obj = *itr; return obj; } template T mset_bisect_right(mset &X, T v){ auto itr = X.upper_bound(v); T obj = *itr; return obj; } // map template pair map_bisect_left(map &X, T v){ auto itr = X.lower_bound(v); pair obj = *itr; return obj; } template pair map_bisect_right(map &X, T v){ auto itr = X.upper_bound(v); pair obj = *itr; return obj; } // input inline void scan(){} template inline void scan(Head&head,Tail&... tail){std::cin >> head; scan(tail...);} #define LL(...) long long __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) long double __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHAR(...) char __VA_ARGS__;scan(__VA_ARGS__) // vector template istream &operator>>(istream &is, vector &v) { for (T &in : v) is >> in; return is; } // print void print() { cout << endl; } template void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward(tail)...); } #ifdef LOCAL # include # define debug(...) cerr << "\033[33m"; debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__); cerr << "\033[m"; #else # define debug(...) ; #endif int main(){ LL(T); rep(_, T){ LL(y, x); ll cnt = x; rep(i, x, 61){ if((y & (1LL << i)) >= 1){ cnt = i; } } debug(cnt); ll ans = 0; rep(i, cnt + 1){ ans += (1LL << i); } print(ans); } }