https://www.acwing.com/problem/content/1348/
#include<bits/stdc++.h>
using namespace std;
#define change(a,b) ((a%b>=10)?(a%b-10+'A'):(a%b+'0'))
int main(){
char ans[10000];
char ans2[10000];
int b;
cin>>b;
for(int i=1;i<=300;i++)
{
int j=0;
int p=i*i;
while(p)
{
ans[j++]=change(p,b);
p/=b;
}
int x=strlen(ans);
int flag=0;
for(int f=0;f<x/2;f++)
{
if(ans[f]!=ans[x-1-f]){flag=1;
break;
}
}
if(!flag){
// cout<<i<<' ';
int p=i;
j=0;
while(p)
{
ans2[j++]=change(p,b);
p/=b;
}
int y=strlen(ans2);
for(int f=y-1;f>=0;f--)
cout<<ans2[f];
cout<<' ';
for(int f=x-1;f>=0;f--)
cout<<ans[f];
cout<<endl;
}
}
return 0;
}