Language: C++

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

                                    #define FOR(i,a,b) for(int i = (a); i < (b); i++)
                                    #define rep(i,n) FOR(i,0,n)
                                    #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
                                    #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
                                    #define FILL(a, value) memset(a, value, sizeof(a)

                                    #define SZ(a) (int)a.size()
                                    #define ALL(a) a.begin(), a.end()
                                    #define PB push_back
                                    #define MP make_pair
                                    #define er erase
                                    #define in insert
                                    #define f first
                                    #define s second




                                    typedef  long long LL;
                                    typedef vector<int> VI;
                                    typedef vector<LL > VL;
                                    typedef vector<vector<int > > VVI;
                                    typedef vector<vector<LL>> VVL;
                                    typedef vector <vector<pair<int, int >> >VVPI;
                                    typedef vector<vector<pair<LL, LL >> >VVPL;
                                    typedef vector<pair<LL, LL >> PL;
                                    typedef vector<PL> VPL;
                                    typedef pair<int, int> PII;
                                    typedef pair<LL,LL > PLL ;
                                    typedef vector<PII> VPI;

                                    const double PI = acos(-1.0);
                                    const int INF = 1e9;
                                    const LL LINF = (LL)1e18 * 5;

                                    const double EPS = 1e-7;
                                    const int MAS =  3 *1e5 + 10;
                                    const int mod = 998244353;
                                    const int MOD =1e9+7;
                                    const int LOG= 19;
                                    const int ar = 1e5 +100;
                                    const int MAX = 1e6 + 1e2;
                                    const int root = 0;


                                void min_self(LL &a ,LL b)
                                {
                                    a = min(a,b);
                                }
                                    LL n,a,b,c,d;

                                map<LL,LL > mp;
                                    LL f(LL nd)
                                {
                                    if(nd == 0 )return 0;
                                    if(nd == 1)return d ;
                                    if(mp.count(nd))return mp[nd];
                                    LL best = LINF ;
                                    if(d < LINF / nd)min_self(best,d * nd);
                                    VL vec = { 2,3,5};
                                    VL cost ={a,b,c};
                                    rep(i,3)
                                    {
                                      int mul = vec[i];
                                      LL price = cost[i];
                                      if(nd % mul == 0)
                                      {
                                            min_self(best,price + f(nd  / mul));
                                      }
                                      else
                                      {
                                          LL eq = nd / mul * mul;
                                          min_self(best,price + (nd - eq)* d + f(nd / mul));
                                          LL eq_up = eq + mul;
                                          min_self(best,price + d *(eq_up - nd ) +f(nd/ mul + 1));
                                      }
                                    }
                                    return mp[nd] = best;

                                }

                                int main() {
                                    ios_base::sync_with_stdio(false);
                                    cin.tie(NULL);
                                    int test_case;
                                    cin >> test_case;
                                    while(test_case--)
                                    {
                                        cin >> n >> a >> b >> c >> d;
                                        cout << f(n) << '\n';
                                        mp.clear();

                                    }

                                }


































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

                                    #define FOR(i,a,b) for(int i = (a); i < (b); i++)
                                    #define rep(i,n) FOR(i,0,n)
                                    #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
                                    #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
                                    #define FILL(a, value) memset(a, value, sizeof(a)

                                    #define SZ(a) (int)a.size()
                                    #define ALL(a) a.begin(), a.end()
                                    #define PB push_back
                                    #define MP make_pair
                                    #define er erase
                                    #define in insert
                                    #define f first
                                    #define s second




                                    typedef  long long LL;
                                    typedef vector<int> VI;
                                    typedef vector<LL > VL;
                                    typedef vector<vector<int > > VVI;
                                    typedef vector<vector<LL>> VVL;
                                    typedef vector <vector<pair<int, int >> >VVPI;
                                    typedef vector<vector<pair<LL, LL >> >VVPL;
                                    typedef vector<pair<LL, LL >> PL;
                                    typedef vector<PL> VPL;
                                    typedef pair<int, int> PII;
                                    typedef pair<LL,LL > PLL ;
                                    typedef vector<PII> VPI;

                                    const double PI = acos(-1.0);
                                    const int INF = 1e9;
                                    const LL LINF = (LL)1e18 * 5;

                                    const double EPS = 1e-7;
                                    const int MAS =  3 *1e5 + 10;
                                    const int mod = 998244353;
                                    const int MOD =1e9+7;
                                    const int LOG= 19;
                                    const int ar = 1e5 +100;
                                    const int MAX = 1e6 + 1e2;
                                    const int root = 0;


                                void min_self(LL &a ,LL b)
                                {
                                    a = min(a,b);
                                }
                                    LL n,a,b,c,d;

                                map<LL,LL > mp;
                                    LL f(LL nd)
                                {
                                    if(nd == 0 )return 0;
                                    if(nd == 1)return d ;
                                    if(mp.count(nd))return mp[nd];
                                    LL best = LINF ;
                                    if(d < LINF / nd)min_self(best,d * nd);
                                    VL vec = { 2,3,5};
                                    VL cost ={a,b,c};
                                    rep(i,3)
                                    {
                                      int mul = vec[i];
                                      LL price = cost[i];
                                      if(nd % mul == 0)
                                      {
                                            min_self(best,price + f(nd  / mul));
                                      }
                                      else
                                      {
                                          LL eq = nd / mul * mul;
                                          min_self(best,price + (nd - eq)* d + f(nd / mul));
                                          LL eq_up = eq + mul;
                                          min_self(best,price + d *(eq_up - nd ) +f(nd/ mul + 1));
                                      }
                                    }
                                    return mp[nd] = best;

                                }

                                int main() {
                                    ios_base::sync_with_stdio(false);
                                    cin.tie(NULL);
                                    int test_case;
                                    cin >> test_case;
                                    while(test_case--)
                                    {
                                        cin >> n >> a >> b >> c >> d;
                                        cout << f(n) << '\n';
                                        mp.clear();

                                    }

                                }






























































Compiler output:
a.cc:167:50: error: redefinition of 'const double PI'
  167 |                                     const double PI = acos(-1.0);
      |                                                  ^~
a.cc:35:50: note: 'const double PI' previously defined here
   35 |                                     const double PI = acos(-1.0);
      |                                                  ^~
a.cc:168:47: error: redefinition of 'const int INF'
  168 |                                     const int INF = 1e9;
      |                                               ^~~
a.cc:36:47: note: 'const int INF' previously defined here
   36 |                                     const int INF = 1e9;
      |                                               ^~~
a.cc:169:46: error: redefinition of 'const LL LINF'
  169 |                                     const LL LINF = (LL)1e18 * 5;
      |                                              ^~~~
a.cc:37:46: note: 'const LL LINF' previously defined here
   37 |                                     const LL LINF = (LL)1e18 * 5;
      |                                              ^~~~
a.cc:171:50: error: redefinition of 'const double EPS'
  171 |                                     const double EPS = 1e-7;
      |                                                  ^~~
a.cc:39:50: note: 'const double EPS' previously defined here
   39 |                                     const double EPS = 1e-7;
      |                                                  ^~~
a.cc:172:47: error: redefinition of 'const int MAS'
  172 |                                     const int MAS =  3 *1e5 + 10;
      |                                               ^~~
a.cc:40:47: note: 'const int MAS' previously defined here
   40 |                                     const int MAS =  3 *1e5 + 10;
      |                                               ^~~
a.cc:173:47: error: redefinition of 'const int mod'
  173 |                                     const int mod = 998244353;
      |                                               ^~~
a.cc:41:47: note: 'const int mod' previously defined here
   41 |                                     const int mod = 998244353;
      |                                               ^~~
a.cc:174:47: error: redefinition of 'const int MOD'
  174 |                                     const int MOD =1e9+7;
      |                                               ^~~
a.cc:42:47: note: 'const int MOD' previously defined here
   42 |                                     const int MOD =1e9+7;
      |                                               ^~~
a.cc:175:47: error: redefinition of 'const int LOG'
  175 |                                     const int LOG= 19;
      |                                               ^~~
a.cc:43:47: note: 'const int LOG' previously defined here
   43 |                                     const int LOG= 19;
      |                                               ^~~
a.cc:176:47: error: redefinition of 'const int ar'
  176 |                                     const int ar = 1e5 +100;
      |                                               ^~
a.cc:44:47: note: 'const int ar' previously defined here
   44 |                                     const int ar = 1e5 +100;
      |                                               ^~
a.cc:177:47: error: redefinition of 'const int MAX'
  177 |                                     const int MAX = 1e6 + 1e2;
      |                                               ^~~
a.cc:45:47: note: 'const int MAX' previously defined here
   45 |                                     const int MAX = 1e6 + 1e2;
      |                                               ^~~
a.cc:178:47: error: redefinition of 'const int root'
  178 |                                     const int root = 0;
      |                                               ^~~~
a.cc:46:47: note: 'const int root' previously defined here
   46 |                                     const int root = 0;
      |                                               ^~~~
a.cc:181:38: error: redefinition of 'void min_self(LL&, LL)'
  181 |                                 void min_self(LL &a ,LL b)
      |                                      ^~~~~~~~
a.cc:49:38: note: 'void min_self(LL&, LL)' previously defined here
   49 |                                 void min_self(LL &a ,LL b)
      |                                      ^~~~~~~~
a.cc:185:40: error: redefinition of 'LL n'
  185 |                                     LL n,a,b,c,d;
      |                                        ^
a.cc:53:40: note: 'LL n' previously declared here
   53 |                                     LL n,a,b,c,d;
      |                                        ^
a.cc:185:42: error: redefinition of 'LL a'
  185 |                                     LL n,a,b,c,d;
      |                                          ^
a.cc:53:42: note: 'LL a' previously declared here
   53 |                                     LL n,a,b,c,d;
      |                                          ^
a.cc:185:44: error: redefinition of 'LL b'
  185 |                                     LL n,a,b,c,d;
      |                                            ^
a.cc:53:44: note: 'LL b' previously declared here
   53 |                                     LL n,a,b,c,d;
      |                                            ^
a.cc:185:46: error: redefinition of 'LL c'
  185 |                                     LL n,a,b,c,d;
      |                                              ^
a.cc:53:46: note: 'LL c' previously declared here
   53 |                                     LL n,a,b,c,d;
      |                                              ^
a.cc:185:48: error: redefinition of 'LL d'
  185 |                                     LL n,a,b,c,d;
      |                                                ^
a.cc:53:48: note: 'LL d' previously declared here
   53 |                                     LL n,a,b,c,d;
      |                                                ^
a.cc:187:45: error: redefinition of 'std::map<long long int, long long int> mp'
  187 |                                 map<LL,LL > mp;
      |                                             ^~
a.cc:55:45: note: 'std::map<long long int, long long int> mp' previously declared here
   55 |                                 map<LL,LL > mp;
      |                                             ^~
a.cc:148:47: error: redefinition of 'LL first(LL)'
  148 |                                     #define f first
      |                                               ^~~~~
a.cc:188:40: note: in expansion of macro 'f'
  188 |                                     LL f(LL nd)
      |                                        ^
a.cc:16:47: note: 'LL first(LL)' previously defined here
   16 |                                     #define f first
      |                                               ^~~~~
a.cc:56:40: note: in expansion of macro 'f'
   56 |                                     LL f(LL nd)
      |                                        ^
a.cc:217:37: error: redefinition of 'int main()'
  217 |                                 int main() {
      |                                     ^~~~
a.cc:85:37: note: 'int main()' previously defined here
   85 |                                 int main() {
      |                                     ^~~~