考察进制转换 直接用string字符串存 很方便的
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
char a[20] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
string conver_to(int num, int b) {
string res;
while (num != 0) {
res += a[(num % b)];
num /= b;
}
reverse(res.begin(), res.end());
return res;
}
int main() {
int b;
cin >> b;
for (int i = 1; i <= 300; i++) {
int temp = i;
string str_number = conver_to(i * i, b); //平方转化为b进制
string temp_str = str_number;
reverse(str_number.begin(), str_number.end());
if (temp_str == str_number) {
cout << conver_to(i, b) << " " << conver_to(i * i, b) << endl;
}
}
return 0;
}