include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
std::string decimalToBase(int n, int base) {
if (n == 0) return “0”;
std::vector<int> digits;
while (n != 0) {
int remainder = n % base;
n /= base;
// 处理负余数
if (remainder < 0) {
remainder += abs(base);
n++; // 向上取整
}
digits.push_back(remainder);
}
// 将结果反转为字符串
std::string result;
for (auto it = digits.rbegin(); it != digits.rend(); ++it) {
// 转换为十六进制字符
if (*it < 10) {
result += std::to_string(*it);
} else {
result += ('A' + (*it - 10)); // 将10-15转换为A-F
}
}
return result;
}
int main() {
int number, base;
std::cin >> number >> base;
std::string representation = decimalToBase(number, base);
std::cout << number << "=" << representation << "(base" << base << ")" << std::endl;
return 0;
}