把题目意思翻译成代码就行了。
1 /*
2 ID:31440461
3 PROG:palsquare
4 LANG:C++
5 */
6 #include<iostream>
7 using namespace std;
8 int B;
9 const
10 int MAX=300;
11 char CH[20]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
12
13 void printdata(int x)
14 {
15 int a[30],i=0;
16 while (x) a[++i]=x%B,x/=B;
17 for (;i;cout<<CH[ a[i--] ]);
18 }
19
20 void handle( int x )
21 {
22 int a[30],n=0,xx=x*x;
23 while (xx)a[++n]=xx%B,xx/=B;
24 int t=n;
25 for (;(n)&&(a[n]==a[t-n+1]);--n);
26 if (n==0) printdata(x),cout<<' ',printdata(x*x),cout<<endl;
27 }
28
29 int main()
30 {
31 freopen("palsquare.in","r",stdin);
32 freopen("palsquare.out","w",stdout);
33 cin>>B;
34 for (int i=1;i<=MAX;i++) handle(i);
35 return 0;
36 }
37