/*
ID:wconvey1
PROG:palsquare
LANG:C++
*/
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int b,i,j,len,len1,n,temp;
char s[20],s1[20];
freopen("palsquare.in","r",stdin);
freopen("palsquare.out","w",stdout);
scanf("%d",&b);
for(i=1;i<=300;i++)
{
int flag=1;
len=len1=0;
n=i*i;
if(1==i) { printf("1 1\n");continue;}
while(n!=0)
{
s[len++]=n%b;
n/=b;
/*if(n%b<10)
s[len++]='n%b';
else
s[len++]='A'+n%b-10;
n/=b;*/
}
for(j=0;j<=(len-1)/2;j++)
if(s[j]!=s[len-1-j])
{
flag=0;
break;
}
if(flag==1)
{
temp=i;
while(temp!=0)
{
s1[len1++]=temp%b;
temp/=b;
/* if(n%b<10)
s[len++]='n%b';
else
s[len++]='A'+n%b-10;
temp/=b;*/
}
for(j=len1-1;j>=0;j--)
{
if(s1[j]>9)
printf("%C",'A'+s1[j]-10);
else
printf("%d",s1[j]);
}
printf(" ");
for(j=0;j<len;j++)
{
if(s[j]>9)
printf("%C",'A'+s[j]-10);
else
printf("%d",s[j]);
}
printf("\n");
}
}
return 0;
}
USACO 1.2.4 Palindromic Squares
最新推荐文章于 2024-05-25 09:55:59 发布