Language: C++

//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(...) qqbx(#__VA_ARGS__,  __VA_ARGS__)
template <typename H, typename ...T> constexpr void qqbx(const char *s, const H &h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, args...); // C++ 17!
}
#else
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) (lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 200025, INF = 1e18, MOD = 1000000007, K = 357, inf = 1e9;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        ll a, b;
        cin >> a >> b;
        auto calc = [&](ll n) {
            if(n == 0) return 0;
            auto f = [&](ll i){
                ll j = n-i;
                return (i+(i>=a)) * (j+(j>=b));
            };
            ll x = 0;
            for(ll s = 1LL<<31; s; s>>=1) if(f(x+s)-f(x+s-1) > 0) x += s;
            if(f(x) < a*b) return n;
            ll l = 0, r = n+1;
            for(ll s = 1LL<<31; s; s>>=1) {
                if(l+s < x && f(l+s) < a*b) l += s;
                if(r-s > x && f(r-s) < a*b) r -= s;
            }
            // f(l) < a*b, f(l+1) >= a*b
            return n - (r-l-1);
        };
        //for(int i = 0; i < 100; i++) cout << calc(i) << ' '; cout << '\n';
        ll x = 0;
        for(ll s = 1LL<<31; s; s>>=1) if(calc(x+s)-calc(x+s-1) > 0) x += s;
        debug(x);
        cout << calc(x)-1 << '\n';
    }
}



Compiler output:
a.cc: In lambda function:
a.cc:68:35: error: inconsistent types 'int' and 'long int' deduced for lambda return type
   68 |             if(f(x) < a*b) return n;
      |                                   ^
a.cc:75:22: error: inconsistent types 'int' and 'long int' deduced for lambda return type
   75 |             return n - (r-l-1);
      |                    ~~^~~~~~~~~