/*
PROG:palsquare
LANG:C++
*/
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
ifstream fin ("palsquare.in");
ofstream fout ("palsquare.out");
int i,j,k,m;
int ary;//进制
fin>>ary;
char a[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
for(i=1;i<=300;i++)
{
string b,d;
m=pow(i,2);
j=i;
while(j!=0)
{
b=b+a[j%ary];
j=j/ary;
}
while(m!=0)
{
d=d+a[m%ary];
m=m/ary;
}
bool c=true;
for(j=0,k=d.length()-1;j<d.length()/2 && k>=d.length()/2;j++,k--)
{
if(d[j]!=d[k])
{
c=false;
break;
}
}
if(c)
{
for(j=b.length()-1;j>=0;j--)
fout<<b[j];
fout<<" ";
for(j=d.length()-1;j>=0;j--)
fout<<d[j];
fout<<endl;
}
}
return 0;
}
palindromic squares
最新推荐文章于 2023-07-15 11:36:27 发布