Language: C++

#include <bits/stdc++.h>
using namespace std;

#define ll long long

ll gcd(ll a, ll b) {
  return b ? gcd(b, a % b) : a;
}
void exgcd(ll a, ll b, ll& x, ll& y) {
  if (!b) {
    x = 1, y = 0;
  } else {
    exgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
}
ll inv(ll a, ll Mod) {
  ll x, y;
  exgcd(a, Mod, x, y);
  return x < 0 ? x + Mod : x;
} 

typedef class vec {
  public:
    ll dx, dy;
    int c;

    vec(ll dx, ll dy, int c) : dx(dx), dy(dy), c(c) { }
} vec;

int T;
ll A, X, B, Y, C;
vector<vec> conv;

void solve() {
  scanf("%lld%lld%lld%lld%lld", &A, &X, &B, &Y, &C);
  ll g = gcd(A, B), ga, gb;
  A /= g, B /= g, C /= gcd(g, C);
  ga = gcd(A, C);
  A /= ga, Y /= ga, C /= ga;
  gb = gcd(B, C);
  B /= gb, X /= gb, C /= gb;
  if (C == 1) {
    printf("%lld\n", X + Y);
    return;
  }

  conv.clear();
  ll W = C, H = A * inv(B, C) % C, x0 = 0, ia = inv(A, C), p = 0, np;
  while (W && H) {
    if (W >= H) {
      ll t = W / H;
      W -= t * H;
      x0 += t * H;
      np = x0 * B % C * ia % C;
      np += !np * C;
      conv.emplace_back((np - p) / t, H, t);
      p = np;
    } else {
      if (!(H % W)) { 
        conv.emplace_back(C - p, W, 1);
        break;
      } else {
        H %= W;
      }
    }
  }

  int l = 1, r = X + Y, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    ll ca = 0, cb = mid * C;
    for (auto v : conv) {
      ll ub = min(ub, 1000000001);
      ca += v.dx * ub;
      cb -= v.dy * ub;
      if (ca > X || cb <= Y) {
        break;
      }
    }
    if (ca <= X && cb <= Y) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  printf("%d\n", l - 1);
}

int main() {
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:74:18: error: no matching function for call to 'min(long long int&, int)'
   74 |       ll ub = min(ub, 1000000001);
      |               ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:74:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   74 |       ll ub = min(ub, 1000000001);
      |               ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:74:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   74 |       ll ub = min(ub, 1000000001);
      |               ~~~^~~~~~~~~~~~~~~~