数据范围很小,1到300
准换后判断即可,符合则输出
/*
ID: xsy97051
LANG: C++
TASK: palsquare
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
char zf[21]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K'};
string zhuan(int m,int n)
{
string st="";
while(m!=0)
{
st+=zf[m%n];
m/=n;
}
int len=st.size();
for(int i=0;i<=(len-1)/2;i++)
swap(st[i],st[len-i-1]);
return st;
}
int pan(string st)
{
for(int i=0;i<st.size();i++)
{
int len=st.size();
if(st[i]!=st[len-i-1]) return 0;
}
return 1;
}
int main()
{
freopen("palsquare.in","r",stdin);
freopen("palsquare.out","w",stdout);
int n;
cin>>n;
for(int i=1;i<=300;i++)
{
int k=i*i;
if(pan(zhuan(k,n))==1)
cout<<zhuan(i,n)<<" "<<zhuan(k,n)<<endl;
}
return 0;
}