#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
char change(int x)
{
if(x < 10) return x + '0';
else return x - 10 + 'A';
}
int change(char c)
{
if('0' <= c && c <= '9') return c - '0';
else return c - 'A' + 10;
}
string solve(long long n,int p)
{
string res = "";
while(n != 0)
{
int r = n % p;
while(r < 0) r -= p;
res = change(r) + res;
n /= p;
}
return res;
}
int main()
{
long long n,p;
cin >> n >> p;
string s = solve(n,p);
cout << n << "=" << s << "(base" << p << ")";
return 0;
}
现在认为是 solve() 有问题这还用说吗。