/*
ID: sdjllyh1
PROG: palsquare
LANG: JAVA
complete date: 2008/9/25
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjls
*/
import java.io.*;
import java.util.*;
public class palsquare
{
private static int base;
public static void main(String[] args) throws IOException
{
init();
runAndOutput();
System.exit(0);
}
private static void init() throws IOException
{
BufferedReader f = new BufferedReader(new FileReader("palsquare.in"));
base = Integer.parseInt(f.readLine());
f.close();
}
private static void runAndOutput() throws IOException
{
String[] squaresInBase = new String[301];
for (int i = 1; i <= 300; i++)
{
squaresInBase[i] = getNumberInBase(i * i);
}
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("palsquare.out")));
for (int i = 1; i <= 300; i++)
{
if (isPalindrome(squaresInBase[i]))
{
out.print(getNumberInBase(i));
out.print(" ");
out.println(squaresInBase[i]);
}
}
out.close();
}
private static String getNumberInBase(int value)
{
String retNumberInBase = "";
while (value > 0)
{
retNumberInBase = numToLetter(value % base) + retNumberInBase;
value = value / base;
}
return retNumberInBase;
}
private static boolean isPalindrome(String num)
{
int length = num.length();
for (int i = 0; i < length /2; i++)
{
if (num.charAt(i) != num.charAt(length - i -1))
{
return false;
}
}
return true;
}
private static String numToLetter(int value)
{
char retLetter ;
if (value<10)
{
retLetter = '0';
retLetter += value;
}
else
{
retLetter = 'A';
retLetter += value - 10;
}
return String.valueOf(retLetter);
}
}
ID: sdjllyh1
PROG: palsquare
LANG: JAVA
complete date: 2008/9/25
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjls
*/
import java.io.*;
import java.util.*;
public class palsquare
{
private static int base;
public static void main(String[] args) throws IOException
{
init();
runAndOutput();
System.exit(0);
}
private static void init() throws IOException
{
BufferedReader f = new BufferedReader(new FileReader("palsquare.in"));
base = Integer.parseInt(f.readLine());
f.close();
}
private static void runAndOutput() throws IOException
{
String[] squaresInBase = new String[301];
for (int i = 1; i <= 300; i++)
{
squaresInBase[i] = getNumberInBase(i * i);
}
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("palsquare.out")));
for (int i = 1; i <= 300; i++)
{
if (isPalindrome(squaresInBase[i]))
{
out.print(getNumberInBase(i));
out.print(" ");
out.println(squaresInBase[i]);
}
}
out.close();
}
private static String getNumberInBase(int value)
{
String retNumberInBase = "";
while (value > 0)
{
retNumberInBase = numToLetter(value % base) + retNumberInBase;
value = value / base;
}
return retNumberInBase;
}
private static boolean isPalindrome(String num)
{
int length = num.length();
for (int i = 0; i < length /2; i++)
{
if (num.charAt(i) != num.charAt(length - i -1))
{
return false;
}
}
return true;
}
private static String numToLetter(int value)
{
char retLetter ;
if (value<10)
{
retLetter = '0';
retLetter += value;
}
else
{
retLetter = 'A';
retLetter += value - 10;
}
return String.valueOf(retLetter);
}
}