回文数算法1
#include
#include
#include
using namespace std;
int a;
char get(int x)
{
if (x <= 9) return ‘0’+x;
return ‘A’+x-10;
}
string g(int n)
{
string s;
while (n) {
s += get(n%a);
n /= a;
}
reverse(s.begin(),s.end());
return s;
}
bool f(string s) {
for (int i = 0, j = s.size()-1; i < j; i++, j–) {
if (s[i] != s[j]) return false;
}
return true;
}
int main()
{
cin >> a;
for (int i = 1; i <= 300; i++) {
string s = g(i*i);
if (f(s)) {
cout << g(i) << " " << s << endl;
}
}
return 0;
}