题目描述:
代码如下:
#include <bits/stdc++.h>
using namespace std;
char get(int x) {
if (x <= 9)
return x + '0';
else
return x - 10 + 'A';
}
string turn(int num, int b) {
string ss;
while (num) {
ss += get(num % b);
num /= b;
}
reverse(ss.begin(), ss.end());
return ss;
}
bool check(string num) {
for (int i = 0, j = num.size() - 1; i < j; i++, j--) {
if (num[i] != num[j])
return false;
}
return true;
}
int main() {
int b;
cin >> b;
for (int i = 1; i <= 300; i++) {
int num = i * i;
string str;
str = turn(num, b);
if (check(str)) {
cout << turn(i, b) << " " << str << endl;
}
}
}