Language: C++

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

map<ll,ll> mcount;
ll a,b,c,d;
ll rec(ll n){
  if(n == 0) return 0;
  if(n == 1) return d;
  if(mcount.count(n)) return mcount[n];

  ll u2 = (n+1)/2*2;
  ll l2 = n/2*2;
  ll u3 = (n+2)/3*3;
  ll l3 = n/3*3;
  ll u5 = (n+4)/5*5;
  ll l5 = n/5*5;

  ll ret = 1e18;
  if(n < 1e18/d) ret = n*d;
  ret = min(ret, llabs(l2-n)*d + a + rec(l2/2));
  ret = min(ret, llabs(u2-n)*d + a + rec(u2/2));

  ret = min(ret, llabs(l3-n)*d + b + rec(l3/3));
  ret = min(ret, llabs(u3-n)*d + b + rec(u3/3));

  ret = min(ret, llabs(l5-n)*d + c + rec(l5/5));
  ret = min(ret, llabs(u5-n)*d + c + rec(u5/5));

  mcount[n] = ret;
  return ret;

}

int main(){
  int t;cin >> t;
  rep(i,t){
    ll n;cin >> n >> a >> b >> c >> d;
    mcount.clear();
    cout << rec(n) << endl;
  }
}


#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;
 
map<ll,ll> mcount;
ll a,b,c,d;
ll rec(ll n){
  if(n == 0) return 0;
  if(n == 1) return d;
  if(mcount.count(n)) return mcount[n];
 
  ll u2 = (n+1)/2*2;
  ll l2 = n/2*2;
  ll u3 = (n+2)/3*3;
  ll l3 = n/3*3;
  ll u5 = (n+4)/5*5;
  ll l5 = n/5*5;
 
  ll ret = 1e18;
  if(n < 1e18/d) ret = n*d;
  ret = min(ret,llabs(u2-n)*d + a + rec(u2/2));
  ret = min(ret,llabs(n-l2)*d + a + rec(l2/2));
  ret = min(ret,llabs(u3-n)*d + b + rec(u3/3));
  ret = min(ret,llabs(n-l3)*d + b + rec(l3/3));
  ret = min(ret,llabs(u5-n)*d + c + rec(u5/5));
  ret = min(ret,llabs(n-l5)*d + c + rec(l5/3));
 
 
  mcount[n] = ret;
  return ret; 
}
 
int main(){
  int t;cin >> t;
  rep(i,t){
    ll n;cin >> n >> a >> b >> c >> d;
    mcount.clear();
    cout << rec(n) << endl;
  }
}

Compiler output:
a.cc:59:5: error: redefinition of 'int INF'
   59 | int INF = 1e9;
      |     ^~~
a.cc:9:5: note: 'int INF' previously defined here
    9 | int INF = 1e9;
      |     ^~~
a.cc:61:12: error: redefinition of 'std::map<long long int, long long int> mcount'
   61 | map<ll,ll> mcount;
      |            ^~~~~~
a.cc:11:12: note: 'std::map<long long int, long long int> mcount' previously declared here
   11 | map<ll,ll> mcount;
      |            ^~~~~~
a.cc:62:4: error: redefinition of 'll a'
   62 | ll a,b,c,d;
      |    ^
a.cc:12:4: note: 'll a' previously declared here
   12 | ll a,b,c,d;
      |    ^
a.cc:62:6: error: redefinition of 'll b'
   62 | ll a,b,c,d;
      |      ^
a.cc:12:6: note: 'll b' previously declared here
   12 | ll a,b,c,d;
      |      ^
a.cc:62:8: error: redefinition of 'll c'
   62 | ll a,b,c,d;
      |        ^
a.cc:12:8: note: 'll c' previously declared here
   12 | ll a,b,c,d;
      |        ^
a.cc:62:10: error: redefinition of 'll d'
   62 | ll a,b,c,d;
      |          ^
a.cc:12:10: note: 'll d' previously declared here
   12 | ll a,b,c,d;
      |          ^
a.cc:63:4: error: redefinition of 'll rec(ll)'
   63 | ll rec(ll n){
      |    ^~~
a.cc:13:4: note: 'll rec(ll)' previously defined here
   13 | ll rec(ll n){
      |    ^~~
a.cc:89:5: error: redefinition of 'int main()'
   89 | int main(){
      |     ^~~~
a.cc:41:5: note: 'int main()' previously defined here
   41 | int main(){
      |     ^~~~