Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int INF = (int)1e18;
vector<int> div(int n) {
  vector<int> ret;
  for(int i = 1; i * i <= n; ++i) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
int N, A; 
map<int, int> memo;
int solve(int n) {
  if(memo.count(n)) return memo[n];
  vector<int> v = div(n);
  int ret = INF;
  for(int k : v) {
    if(k == n) continue;
    ret = min(ret, solve(k) + n / k + A);
  }
  // cerr << "solve(" << n << ")=" << ret << endl;
  return memo[n] = ret;
}
typedef pair<int, int> P;
struct Node {
  int x, a, d;
  Node(int x_, int a_, int d_) : x(x_), a(a_), d(d_) {}
  bool operator <(const Node& other) const {
    return d > other.d;
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin >> N >> A;
  if(false) {
  // if(N <= 1000000 && A <= 1000000) {
    vector<int> start(N + 1, INF);
    start[1] = 0;
    int ans = INF;
    for(int a = 1; a <= N; ++a) {
      // cerr << "start[" << a << "]=" << start[a] << endl;
      if(ans > start[a] + (N + a - 1) / a) {
        // cerr << "target a=" << a << endl;
      }
      ans = min(ans, start[a] + (N + a - 1) / a);
      for(int j = 1; a * j <= N; ++j) {
        start[a * j] = min(start[a * j], start[a] + j + A);
      }
    }
    cout << ans << endl;
  }
  else {
    // int ans = INF;
    // vector<int> v = div(N);
    // memo[1] = 0;
    // for(int k : v) {
    //   ans = min(ans, solve(k) + N / k);
    // }
    // cout << ans << endl;
    int ans = INF;
    priority_queue<Node> Q;
    Q.emplace(0, 1, 0);
    map<P, int> D;
    D[P(0, 1)] = 0;
    while(!Q.empty()) {
      Node p = Q.top(); Q.pop();
      if(p.d >= ans) break;
      ans = min(ans, (N - p.x + p.a - 1) / p.a + p.d);
      if(p.d + A + (N + p.x - 1) / max(p.x, 1) <= ans) {
        if(D.count(P(p.x + p.a, p.a)) == false || D[P(p.x + p.a, p.a)] > p.d + 1) {
          D[P(p.x + p.a, p.a)] = p.d + 1;
          Q.emplace(p.x + p.a, p.a, p.d + 1);
        }
        if(D.count(P(0, p.x)) == false || D[P(0, p.x)] > p.d + A) {
          D[P(0, p.x)] = p.d + A;
          Q.emplace(0, p.x, p.d + A);
        }
      }
    }
    cout << ans << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:39: error: no matching function for call to 'max(long long int&, int)'
   78 |       if(p.d + A + (N + p.x - 1) / max(p.x, 1) <= ans) {
      |                                    ~~~^~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:78:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   78 |       if(p.d + A + (N + p.x - 1) / max(p.x, 1) <= ans) {
      |                                    ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:78:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   78 |       if(p.d + A + (N + p.x - 1) / max(p.x, 1) <= ans) {
      |                                    ~~~^~~~~~~~