(暴力枚举 通俗易懂)
#include<iostream>
using namespace std;
char conv[20] = {'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J'};
// 将一个数x转化为b进制数
string toStr(int x, int b) {
string ans = "";
while(x) {
ans = conv[x % b] + ans;
x /= b;
}
return ans;
}
// 判断字符串是否为回文
bool verify(string s) {
int h = 0, t = s.size() - 1;
while(h < t) {
if(s[h] != s[t]) {
return false;
}
h++, t--;
}
return true;
}
int main() {
int b;
cin >> b;
for(int i = 1; i <= 300; ++i) {
string s = toStr(i * i, b);
if(verify(s)) cout << toStr(i, b) << ' ' << s << endl;
}
return 0;
}