Language: C++

#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &s)
{
	s = 0;char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) s = ((s+(s<<2))<<1)+ch-'0',ch = getchar();
}
int T;
long long n,A,B,C,D;
map <long long,long long> mp;
priority_queue < pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>> >Q;
inline long long Div2(long long x)
{
	if(x/2 > 1000000000) return A;
	return min(x/2*D,A);
}
inline long long Div2(long long x)
{
	if(x/3 > 1000000000) return A;
	return min(x/3*2*D,A);
}
inline long long Div2(long long x)
{
	if(x/5 > 1000000000) return A;
	return min(x/5*4*D,A);
}
inline void push(pair<long long,long long> A)
{
	if(A.second != n && (!mp[A.second] || mp[A.second] > A.first)) mp[A.second] = A.first,Q.push(A);
}
int main()
{
	// freopen("1.out","w",stdout);
	read(T);
	while(T--)
	{
		read(n),read(A),read(B),read(C),read(D),mp.clear();
		while(!Q.empty()) Q.pop();
		Q.push(make_pair(0ll,n)),mp[n] = 0;
		while(!Q.empty())
		{
			long long x = Q.top().first,y = Q.top().second;Q.pop();
			// cout << "mp[" << y << "]" << x << endl;
			if(y == 0) {printf("%lld\n",x);break;}
			push(make_pair(x+Div2(y-y%2)+(y%2) * D,y/2));
			if(y%2 == 1) push(make_pair(x+Div2(y+1)+D,y/2+1));
			if(y%3 <= 1) push(make_pair(x+Div3(y-y%3)+(y%3) * D,y/3));
			else push(make_pair(x+Div3(y+1)+D,y/3+1));
			if(y%5 <= 2) push(make_pair(x+Div5(y-y%5)+(y%5) * D,y/5));
			else push(make_pair(x+Div5(y+(5-y%5))+(5-(y%5)) * D,y/5+1));
			while(!Q.empty() && mp[Q.top().second] != Q.top().first) Q.pop();
		}
	}
}


Compiler output:
a.cc:18:18: error: redefinition of 'long long int Div2(long long int)'
   18 | inline long long Div2(long long x)
      |                  ^~~~
a.cc:13:18: note: 'long long int Div2(long long int)' previously defined here
   13 | inline long long Div2(long long x)
      |                  ^~~~
a.cc:23:18: error: redefinition of 'long long int Div2(long long int)'
   23 | inline long long Div2(long long x)
      |                  ^~~~
a.cc:13:18: note: 'long long int Div2(long long int)' previously defined here
   13 | inline long long Div2(long long x)
      |                  ^~~~
a.cc: In function 'int main()':
a.cc:48:55: error: 'Div3' was not declared in this scope; did you mean 'Div2'?
   48 |                         if(y%3 <= 1) push(make_pair(x+Div3(y-y%3)+(y%3) * D,y/3));
      |                                                       ^~~~
      |                                                       Div2
a.cc:49:47: error: 'Div3' was not declared in this scope; did you mean 'Div2'?
   49 |                         else push(make_pair(x+Div3(y+1)+D,y/3+1));
      |                                               ^~~~
      |                                               Div2
a.cc:50:55: error: 'Div5' was not declared in this scope; did you mean 'Div2'?
   50 |                         if(y%5 <= 2) push(make_pair(x+Div5(y-y%5)+(y%5) * D,y/5));
      |                                                       ^~~~
      |                                                       Div2
a.cc:51:47: error: 'Div5' was not declared in this scope; did you mean 'Div2'?
   51 |                         else push(make_pair(x+Div5(y+(5-y%5))+(5-(y%5)) * D,y/5+1));
      |                                               ^~~~
      |                                               Div2