SRM519 Div1 Easy - BinaryCards

問題

 なんだっけ。

解法

 なるほどなぁ。

コード

#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

class BinaryCards {
public:
    long long largestNumber(long long A, long long B) {
        if (A == B) {
            return B;
        }
        ll ans = 0;
        while (true) {
            ll a = f(A);
            ll b = f(B);
            if (a != b) {
                return ans + b * 2 - 1;
            }
            ans += a;
            A -= a;
            B -= b;
        }
    }
private:
    ll f(ll x) {
        for (ll i = 1; ; i *= 2) {
            if (i > x) {
                return i / 2;
            }
        }
    }
};