Language: C++

#include <bits/stdc++.h>
using namespace std;
long long one(long long x,long long res,long long answer,long long d){
  long long i=0;
  long long z=min(res,x);
  while(1){
    if(x%z==0){
      long long p=res/z;
      answer+=p*d;
      res%=z;
      break;
    }
    z--;
  }
  if(res==0) return answer;
  else return one(x,res,answer,d);
}      
long long m(long long n){
  if(n/2==0) return 0;
  else return m(n/2)+1;
}
long long m1(long long n){
  if(n/3==0) return 0;
  else return m1(n/3)+1;
}
long long m2(long long n){
  if(n/5==0) return 0;
  else return m2(n/5)+1;
}
int main() {
  long long t;
  cin>>t;
  for(int i=0;i<t;i++){
    long long q=1;
    long long n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    long long ans=1000000000000000000;
    long long inf=m(n)+1;
    for(long long two=0;two<=inf;two++){
      if(two!=0) q*=2;
      long long sup=n/q;
      long long supe=m1(sup)+1;
      long long r=1;
      for(long long three=0;three<=supe;three++){
        if(three!=0) r*=3;
        long long su=sup/r;
        long long super=m2(su)+1;
        long long s=1;
        for(long long five=0;five<=super;five++){
          if(five!=0) s*=5#include <bits/stdc++.h>
using namespace std;
long long one(long long x,long long res,long long answer,long long d){
  long long i=0;
  long long z=min(res,x);
  while(1){
    if(x%z==0){
      long long p=res/z;
      answer+=p*d;
      res%=z;
      break;
    }
    z--;
  }
  if(res==0) return answer;
  else return one(x,res,answer,d);
}      
long long m(long long n){
  if(n/2==0) return 0;
  else return m(n/2)+1;
}
long long m1(long long n){
  if(n/3==0) return 0;
  else return m1(n/3)+1;
}
long long m2(long long n){
  if(n/5==0) return 0;
  else return m2(n/5)+1;
}
int main() {
  long long t;
  cin>>t;
  for(int i=0;i<t;i++){
    long long q=1;
    long long n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    long long ans=1000000000000000000;
    long long inf=m(n)+1;
    for(long long two=0;two<=inf;two++){
      if(two!=0) q*=2;
      long long sup=n/q;
      long long supe=m1(sup)+1;
      long long r=1;
      for(long long three=0;three<=supe;three++){
        if(three!=0) r*=3;
        long long su=sup/r;
        long long super=m2(su)+1;
        long long s=1;
        for(long long five=0;five<=super;five++){
          if(five!=0) s*=5;
          long long x=q*r*s;
          long long answer;
          long long x=q*r*s;
          long long answer=d+two*a+three*b+five*c;
          long long res=abs(n-x);
          long long l=answer;
          if(res!=0) l=one(x,res,answer,d);
          ans=min(l,ans);
        }
      }
    }
    cout<<ans<<endl;
  }
}

Compiler output:
a.cc:50:27: error: stray '#' in program
   50 |           if(five!=0) s*=5#include <bits/stdc++.h>
      |                           ^
a.cc: In function 'int main()':
a.cc:50:27: error: expected ';' before 'include'
   50 |           if(five!=0) s*=5#include <bits/stdc++.h>
      |                           ^~~~~~~~
      |                           ;
a.cc:52:70: error: a function-definition is not allowed here before '{' token
   52 | long long one(long long x,long long res,long long answer,long long d){
      |                                                                      ^
a.cc:67:25: error: a function-definition is not allowed here before '{' token
   67 | long long m(long long n){
      |                         ^
a.cc:71:26: error: a function-definition is not allowed here before '{' token
   71 | long long m1(long long n){
      |                          ^
a.cc:75:26: error: a function-definition is not allowed here before '{' token
   75 | long long m2(long long n){
      |                          ^
a.cc:79:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   79 | int main() {
      |         ^~
a.cc:79:9: note: remove parentheses to default-initialize a variable
   79 | int main() {
      |         ^~
      |         --
a.cc:79:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:79:12: error: a function-definition is not allowed here before '{' token
   79 | int main() {
      |            ^
a.cc:113:2: error: expected '}' at end of input
  113 | }
      |  ^
a.cc:49:49: note: to match this '{'
   49 |         for(long long five=0;five<=super;five++){
      |                                                 ^
a.cc:113:2: error: expected '}' at end of input
  113 | }
      |  ^
a.cc:44:49: note: to match this '{'
   44 |       for(long long three=0;three<=supe;three++){
      |                                                 ^
a.cc:113:2: error: expected '}' at end of input
  113 | }
      |  ^
a.cc:39:40: note: to match this '{'
   39 |     for(long long two=0;two<=inf;two++){
      |                                        ^
a.cc:113:2: error: expected '}' at end of input
  113 | }
      |  ^
a.cc:33:23: note: to match this '{'
   33 |   for(int i=0;i<t;i++){
      |                       ^
a.cc:113:2: error: expected '}' at end of input
  113 | }
      |  ^
a.cc:30:12: note: to match this '{'
   30 | int main() {
      |            ^